From 7367cf0d6bf4e9962ed0c8dd51efd620b35ed04d Mon Sep 17 00:00:00 2001 From: Sergey Mitroshin Date: Thu, 24 Oct 2024 09:10:10 -0400 Subject: [PATCH] Blocks: initialize connection assets in Story block (#39870) Initialize connection assets in the Story block to fix the block assets loading issue. --- .../changelog/fix-jetpack-story-block-connection-assets | 5 +++++ .../packages/connection/src/class-connection-assets.php | 3 +++ .../changelog/fix-jetpack-story-block-connection-assets | 4 ++++ projects/plugins/jetpack/extensions/blocks/story/story.php | 6 ++++++ 4 files changed, 18 insertions(+) create mode 100644 projects/packages/connection/changelog/fix-jetpack-story-block-connection-assets create mode 100644 projects/plugins/jetpack/changelog/fix-jetpack-story-block-connection-assets diff --git a/projects/packages/connection/changelog/fix-jetpack-story-block-connection-assets b/projects/packages/connection/changelog/fix-jetpack-story-block-connection-assets new file mode 100644 index 0000000000000..4652d98b066f2 --- /dev/null +++ b/projects/packages/connection/changelog/fix-jetpack-story-block-connection-assets @@ -0,0 +1,5 @@ +Significance: patch +Type: added +Comment: PHPDoc comment change. + + diff --git a/projects/packages/connection/src/class-connection-assets.php b/projects/packages/connection/src/class-connection-assets.php index f231aa40b7b9e..93daae1b536f7 100644 --- a/projects/packages/connection/src/class-connection-assets.php +++ b/projects/packages/connection/src/class-connection-assets.php @@ -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() { diff --git a/projects/plugins/jetpack/changelog/fix-jetpack-story-block-connection-assets b/projects/plugins/jetpack/changelog/fix-jetpack-story-block-connection-assets new file mode 100644 index 0000000000000..bbca92108485e --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-jetpack-story-block-connection-assets @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Blocks: initialize connection assets in Story block. diff --git a/projects/plugins/jetpack/extensions/blocks/story/story.php b/projects/plugins/jetpack/extensions/blocks/story/story.php index f279d0ee807b3..9554994db0f4e 100644 --- a/projects/plugins/jetpack/extensions/blocks/story/story.php +++ b/projects/plugins/jetpack/extensions/blocks/story/story.php @@ -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; @@ -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();