Skip to content

Block Editor: Load script modules from enqueue_block_assets in the iframe - #86833

Draft
ellatrix wants to merge 1 commit into
trunkfrom
fix/64482-iframe-script-modules
Draft

ellatrix wants to merge 1 commit into
trunkfrom
fix/64482-iframe-script-modules

Conversation

@ellatrix

@ellatrix ellatrix commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What?

Fixes #64482.

Script modules enqueued with wp_enqueue_script_module() in enqueue_block_assets now run inside the editor canvas iframe (post editor and Site Editor), like styles and classic scripts do.

Why?

They ran in the editor's main window and on the front end, but never in the canvas, so blocks that rely on them didn't work in the editor. #69351 reports the same symptom.

How?

A copy of core's _wp_get_iframed_editor_assets() in lib/compat/wordpress-7.3, swapped in through block_editor_settings_all (the same way #49655 did). Besides styles and scripts, it collects script modules: it uses a clone of $wp_script_modules with an empty queue (registrations kept) while enqueue_block_assets runs, then prints the import map and the enqueued modules into the iframe's scripts. The return shape and the iframe JS don't change.

Core ticket: https://core.trac.wordpress.org/ticket/64360. @sirreal's WordPress/wordpress-develop#10597 and #73765 solve this with a new wp_print_iframe_html action and an html key; this PR is a smaller version that keeps the existing API.

Testing Instructions

  1. Open the Playground with this PR. It adds a plugin that enqueues a script module in enqueue_block_assets. The module adds a red label in each document it runs in.
  2. The post editor shows "Script module ran in: editor canvas iframe" at the top left of the canvas, and "main window" at the bottom right. On trunk only the "main window" label shows.
  3. Open Appearance > Editor and edit a template. Same result.

The new e2e tests in iframed-equeue-block-assets.spec.js (post editor and Site Editor) fail on trunk and pass with this change.

Testing Instructions for Keyboard

No UI change.

Screenshots or screencast

Before After
Before: Site Editor After: Site Editor
Before: post editor After: post editor

Use of AI Tools

Written with Claude Code (Claude Opus 5.5), reviewed by me.

🤖 Generated with Claude Code

Partly automated with help from Claude.

…rame

Script modules enqueued with wp_enqueue_script_module() in
enqueue_block_assets ran in the editor's main window but not in the
canvas iframe. Collect them like styles and scripts and print the
import map and module tags into the iframe's scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

📦 Bundle size

Size Change: 0 B

Total Size: 8.65 MB

98013c0 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric b82f404 trunk % Change
timeToFirstByte 60.8 ms +12.99% -3.29% 60.3 ms +5.22% -3.57% 0.83%
largestContentfulPaint 100 ms +6% -4% 96 ms +0% -4.17% 4.17%
lcpMinusTtfb 36.7 ms +9.67% -11.72% 31.5 ms +18.25% -3.33% 16.51%
wpBeforeTemplate 31.49 ms +13.59% -2% 31.13 ms +7.48% -2.73% 1.16%
wpTemplate 24.56 ms +7.74% -3.62% 24.74 ms +3.68% -8.41% -0.73%
wpTotal 56.79 ms +11.67% -3.03% 56.14 ms +5.81% -3.58% 1.16%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.47%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric b82f404 trunk % Change
timeToFirstByte 49.95 ms +2.2% -3.4% 50.2 ms +3.19% -3.98% -0.5%
largestContentfulPaint 84 ms +4.76% -0% 88 ms +2.27% -4.55% -4.55%
lcpMinusTtfb 35.95 ms +4.03% -3.2% 36.45 ms +2.47% -3.29% -1.37%
wpBeforeTemplate 28.49 ms +3.9% -3.3% 28.14 ms +5.58% -3.2% 1.24%
wpTemplate 18 ms +2.06% -3.61% 18.17 ms +4.29% -5.56% -0.94%
wpTotal 46.84 ms +1.52% -4.23% 46.95 ms +3.13% -4.28% -0.23%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.58%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric b82f404 trunk % Change
mediaProcessingJpeg 406.33 ms +1.66% -0.21% 409.31 ms +1.19% -0.57% -0.73%
mediaProcessingAvif 6218.12 ms +0.13% -0.18% 6221.46 ms +0.38% -0.01% -0.05%
mediaProcessingJpegToAvif 4274.91 ms +0.27% -0.11% 4303.6 ms +0.29% -0.19% -0.67%

media-upload

Metric b82f404 trunk % Change
jpegUploadProcessing 2035.8 ms +1.52% -3.65% 1979.47 ms +1.82% -17.83% 2.85%
pngUploadProcessing 287.47 ms +2.67% -2.71% 279.51 ms +1.36% -2.56% 2.85%
largeJpegUploadProcessing 1993.46 ms +0.79% -0.8% 1984.74 ms +0.89% -24.64% 0.44%
multipleImageUploadProcessing 2094.81 ms +0.61% -0.36% 2128.52 ms +0.53% -1.53% -1.58%

post-editor

Metric b82f404 trunk % Change
serverResponse 264.16 ms +1.06% -6.54% 275.31 ms +3.53% -8.92% -4.05%
firstPaint 279.4 ms +9.15% -9.62% 285.84 ms +5.91% -4.42% -2.25%
domContentLoaded 520.9 ms +1.05% -0.6% 557.43 ms +1.79% -4.88% -6.55%
loaded 521.66 ms +1.04% -0.62% 558.35 ms +1.8% -4.9% -6.57%
firstContentfulPaint 305.58 ms +2.04% -3.14% 318.48 ms +1.44% -4.77% -4.05%
firstBlock 1380.29 ms +4.12% -1.77% 1439.54 ms +5.56% -1.28% -4.12%
type 17.86 ms +22.9% -11.76% 12.93 ms +8.12% -8.51% 38.13%
typeWithoutInspector 13.75 ms +5.96% -12.65% 14.43 ms +34.86% -7% -4.71%
typeWithTopToolbar 21.38 ms +3.88% -3.18% 17.89 ms +11.24% -3.02% 19.51%
typeContainer 6.7 ms +7.31% -16.12% 6.21 ms +8.53% -10.14% 7.89%
focus 90.46 ms +9.52% -5.23% 78.36 ms +10.85% -2.82% 15.44%
firstFocus 198.03 ms +0% -0% 186.96 ms +0% -0% 5.92%
selectAll 274.46 ms +0.43% -0.83% 250.14 ms +3.88% -3.48% 9.72%
undo 22.57 ms +8.86% -4.52% 23.39 ms +10.65% -4.45% -3.51%
listViewOpen 52.61 ms +11.63% -8.15% 50.88 ms +18.55% -13.03% 3.4%
inserterOpen 29.51 ms +7.76% -10.61% 27.51 ms +5.67% -1.45% 7.27%
inserterHover 9.59 ms +6.57% -3.65% 8.32 ms +4.81% -8.29% 15.26%
inserterSearch 6.51 ms +5.38% -3.99% 6.42 ms +17.6% -7.94% 1.4%
loadPatterns 486.41 ms +2.86% -2.08% 422.76 ms +3.1% -3.03% 15.06%
wpTotal 257.24 ms +1.12% -6.7% 268.26 ms +3.25% -9.11% -4.11%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.28%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric b82f404 trunk % Change
serverResponse 313.51 ms +5.6% -5.86% 313.08 ms +1.86% -3.5% 0.14%
firstPaint 386.33 ms +3.39% -2.74% 347.51 ms +7.39% -10.64% 11.17%
domContentLoaded 715.82 ms +1.06% -5.47% 656.06 ms +3.75% -1.55% 9.11%
loaded 716.67 ms +1.08% -5.46% 656.77 ms +3.8% -1.52% 9.12%
firstContentfulPaint 418.24 ms +0.88% -6.98% 369.1 ms +3.52% -1.23% 13.31%
firstBlock 2119.1 ms +1.25% -2.07% 1977.51 ms +1.45% -0.35% 7.16%
type 15.54 ms +13.45% -6.76% 14.01 ms +5.92% -5.5% 10.92%
navigate 102.05 ms +1.1% -4.48% 88.86 ms +5.31% -6.66% 14.84%
loadPatterns 1262.96 ms +2.28% -10.39% 1129.07 ms +10.87% -1.66% 11.86%
loadPages 955.3 ms +1.85% -3.05% 919.26 ms +5.84% -1.46% 3.92%
wpTotal 305.04 ms +5.79% -6.03% 304.78 ms +1.78% -3.6% 0.09%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.29%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

98013c0 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

reflects the room for notes in the menu in /test/e2e/specs/editor/various/block-notes-floating.spec.js, passed after 1 failed attempt.
Error: locator.focus: Error: strict mode violation: getByRole('region', { name: 'Editor top bar' }).getByRole('button', { name: 'Options' }) resolved to 2 elements:
    1) <button id="_r_14_" type="button" tabindex="-1" aria-haspopup="true" aria-label="Options" aria-expanded="false" data-toolbar-item="true" class="components-button components-dropdown-menu__toggle has-icon">…</button> aka getByRole('toolbar', { name: 'Block tools' }).getByRole('button', { name: 'Options' })
    2) <button tabindex="0" type="button" id="base-ui-_r_i_" aria-haspopup="menu" aria-label="Options" aria-expanded="false" class="components-button is-compact has-icon">…</button> aka locator('#base-ui-_r_i_')

Call log:
  - waiting for getByRole('region', { name: 'Editor top bar' }).getByRole('button', { name: 'Options' })

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-notes-floating.spec.js:1248:6
should apply a named font size using the font size buttons in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"large"} -->
+ <!-- wp:paragraph {"fontSize":"medium"} -->
- <p class="has-large-font-size">Paragraph to be made "large"</p>
+ <p class="has-medium-font-size">Paragraph to be made "large"</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:153:6
should reset a named font size using input field in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"small"} -->
+ <!-- wp:paragraph {"fontSize":"tiny"} -->
- <p class="has-small-font-size">Paragraph with font size reset using input field</p>
+ <p class="has-tiny-font-size">Paragraph with font size reset using input field</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:216:6
should reset a named font size using the tools panel menu in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"medium"} -->
+ <!-- wp:paragraph {"fontSize":"small"} -->
- <p class="has-medium-font-size">Paragraph with font size reset using tools panel menu</p>
+ <p class="has-small-font-size">Paragraph with font size reset using tools panel menu</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:178:6

98013c0 Run

@github-actions github-actions Bot added the [Package] E2E Tests /packages/e2e-tests label Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] E2E Tests /packages/e2e-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ES Modules enqueued during enqueue_block_assets are not loaded in the framed editor

1 participant