From 89ef6a94f43b2ccb23baea7d10b7fc2c9b08c04f Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Fri, 5 Jun 2026 17:15:27 +0200 Subject: [PATCH] Pattern creator: stop block styles leaking into the editor's outer page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit enqueue_block_frontend_styles_for_canvas() (added in #740) enqueues every registered block's frontend style on enqueue_block_assets so they are captured into the iframe canvas. That action also fires on the outer creator page's normal front-end render, where it printed every block stylesheet into . The outer shell renders no blocks, so those styles were pure leakage — and Gutenberg's iframe onLoad cloned each one into the canvas, logging a " was added to the iframe incorrectly" warning per style (the wporg-* and jetpack-* handles seen in the console; core wp-* styles are exempted). Gate the enqueue to the iframed-asset capture only. Core brackets that capture's enqueue_block_assets dispatch with a should_load_block_editor_scripts_and_styles => __return_false filter, so its presence distinguishes the capture from the outer render. Verified in wp-env: post-fix the style is no longer enqueued on the outer page (no warning) but is still enqueued during the capture (canvas styles preserved, no #740 regression). Co-Authored-By: Claude Opus 4.8 --- .../plugins/pattern-creator/pattern-creator.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/public_html/wp-content/plugins/pattern-creator/pattern-creator.php b/public_html/wp-content/plugins/pattern-creator/pattern-creator.php index 6ece8ccc..2dfccac4 100644 --- a/public_html/wp-content/plugins/pattern-creator/pattern-creator.php +++ b/public_html/wp-content/plugins/pattern-creator/pattern-creator.php @@ -210,12 +210,26 @@ function inject_editor_template( $template ) { * * Mirroring the fix proposed for WordPress core (_wp_get_iframed_editor_assets should loop * over style_handles too), we enqueue them here so they are captured in the same window. + * + * enqueue_block_assets also fires on the outer creator page's normal front-end render. + * Enqueuing there would print every block's frontend stylesheet into the outer , + * where Gutenberg's iframe onLoad clones each one into the canvas and logs a + * " was added to the iframe incorrectly" warning. The outer page renders no + * blocks, so those styles are pure leakage. _wp_get_iframed_editor_assets() brackets its + * enqueue_block_assets dispatch with a `should_load_block_editor_scripts_and_styles` => + * __return_false filter; its presence is what distinguishes the capture from the outer + * render, so we only enqueue when that filter is active. */ function enqueue_block_frontend_styles_for_canvas() { if ( ! should_load_creator() ) { return; } + // Only run inside the iframed-editor asset capture, not on the outer page. + if ( false === has_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' ) ) { + return; + } + $block_registry = \WP_Block_Type_Registry::get_instance(); foreach ( $block_registry->get_all_registered() as $block_type ) { if ( isset( $block_type->style_handles ) && is_array( $block_type->style_handles ) ) {