Skip to content

Commit

Permalink
Blocks: initialize connection assets in Story block (#39870)
Browse files Browse the repository at this point in the history
Initialize connection assets in the Story block to fix the block assets loading issue.
  • Loading branch information
sergeymitr authored Oct 24, 2024
1 parent 6409452 commit 7367cf0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: PHPDoc comment change.


3 changes: 3 additions & 0 deletions projects/packages/connection/src/class-connection-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public static function configure() {

/**
* Register assets.
*
* NOTICE: Please think twice before including Connection scripts in the frontend.
* Those scripts are intended to be used in WP admin area.
*/
public static function register_assets() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Blocks: initialize connection assets in Story block.
6 changes: 6 additions & 0 deletions projects/plugins/jetpack/extensions/blocks/story/story.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Automattic\Jetpack\Extensions\Story;

use Automattic\Jetpack\Blocks;
use Automattic\Jetpack\Connection\Connection_Assets;
use Jetpack;
use Jetpack_Gutenberg;
use Jetpack_PostImages;
Expand Down Expand Up @@ -442,6 +443,11 @@ function render_block( $attributes ) {
// Let's use a counter to have a different id for each story rendered in the same context.
static $story_block_counter = 0;

if ( 0 === $story_block_counter ) {
// @todo Fix the webpack tree shaking so the block's view.js no longer depends on jetpack-connection, then remove this.
Connection_Assets::register_assets();
}

Jetpack_Gutenberg::load_assets_as_required( __DIR__ );

$media_files = isset( $attributes['mediaFiles'] ) ? enrich_media_files( $attributes['mediaFiles'] ) : array();
Expand Down

0 comments on commit 7367cf0

Please sign in to comment.