Skip to content

Scripts: Preserve static and dynamic imports of script modules - #87098

Draft
luisherranz wants to merge 12 commits into
trunkfrom
fix/wp-scripts-module-import-kinds
Draft

luisherranz wants to merge 12 commits into
trunkfrom
fix/wp-scripts-module-import-kinds

Conversation

@luisherranz

Copy link
Copy Markdown
Member

What?

Preserve static import declarations and dynamic import() calls for external script modules in wp-scripts builds, even when the same source file uses both forms for the same module.

Why?

Webpack’s external configuration can turn a static import into a dynamic one or make an on-demand import static. That changes when the browser loads the dependency.

How?

Use webpack’s module-import external type and keep dynamic imports separate from static imports of the same module. The generated asset file still lists each dependency once, with static taking precedence. The dependency extraction plugin now requires webpack 5.95 or later; wp-scripts already meets that requirement.

Testing Instructions

  1. Build a block whose view module imports @wordpress/a11y both statically and with import(), using wp-scripts build --experimental-modules. Verify that the emitted JavaScript contains both forms and the asset file lists the dependency once, as static.
  2. Repeat with wp-scripts start --experimental-modules. Edit the source to trigger a rebuild and verify that both import forms remain.

Use of AI Tools

100% of the code, tests, and comments in this PR were autonomously generated by AI and reviewed by @luisherranz before the PR was opened.

@github-actions

github-actions Bot commented Nov 19, 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.68 MB

414e4a6 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 863c723 trunk % Change
timeToFirstByte 54.9 ms +10.2% -2.82% 56 ms +10.54% -3.84% -1.96%
largestContentfulPaint 92 ms +6.52% -8.7% 90 ms +8.89% -6.67% 2.22%
lcpMinusTtfb 31.45 ms +24.01% -6.68% 30.55 ms +24.55% -8.35% 2.95%
wpBeforeTemplate 28.09 ms +14.49% -1.25% 28.73 ms +8.98% -3.79% -2.23%
wpTemplate 22.39 ms +3.17% -3.71% 23.02 ms +3.91% -4.3% -2.74%
wpTotal 50.69 ms +10.32% -3.16% 51.77 ms +11.34% -4.06% -2.09%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 863c723 trunk % Change
timeToFirstByte 46.65 ms +6.65% -3.32% 44.95 ms +8.45% -1.89% 3.78%
largestContentfulPaint 84 ms +4.76% -4.76% 80 ms +5% -0% 5%
lcpMinusTtfb 37.05 ms +6.88% -5.53% 35.25 ms +2.41% -5.82% 5.11%
wpBeforeTemplate 25.02 ms +11.91% -2.48% 24.15 ms +11.84% -1.82% 3.6%
wpTemplate 17.57 ms +3.59% -3.64% 17.02 ms +9.46% -1.76% 3.23%
wpTotal 43.02 ms +4.35% -2.86% 41.35 ms +9.67% -2.06% 4.04%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 863c723 trunk % Change
mediaProcessingJpeg 424.73 ms +0.68% -1.69% 418.37 ms +0.97% -0.17% 1.52%
mediaProcessingAvif 6259.05 ms +0.34% -0.24% 6259.28 ms +0.05% -0.66% 0%
mediaProcessingJpegToAvif 4391.28 ms +0.21% -0.39% 4385.03 ms +0.2% -0.33% 0.14%

media-upload

Metric 863c723 trunk % Change
jpegUploadProcessing 2016.26 ms +1.9% -0.61% 1762.94 ms +12.68% -12.26% 14.37%
pngUploadProcessing 274.31 ms +4.14% -0.96% 287.65 ms +1.36% -2.97% -4.64%
largeJpegUploadProcessing 2001.92 ms +1.91% -0.18% 2003.45 ms +0.94% -0.57% -0.08%
multipleImageUploadProcessing 2128.33 ms +0.67% -3.97% 2096.56 ms +1.32% -1.35% 1.52%

post-editor

Metric 863c723 trunk % Change
serverResponse 485.12 ms +3.83% -8.96% 487.17 ms +2.88% -0.81% -0.42%
firstPaint 408.91 ms +7.08% -3.77% 427.51 ms +5.06% -2.09% -4.35%
domContentLoaded 819.65 ms +2.5% -0.77% 815.06 ms +1.76% -1.67% 0.56%
loaded 820.86 ms +2.5% -0.79% 816.04 ms +1.77% -1.64% 0.59%
firstContentfulPaint 463.68 ms +2.77% -0.68% 454.46 ms +4.46% -1.17% 2.03%
firstBlock 2168.15 ms +1.71% -0.57% 2197.49 ms +0.54% -1.57% -1.34%
type 17.14 ms +3.68% -10.27% 18.11 ms +24.19% -6.41% -5.36%
typeWithoutInspector 17.12 ms +1.11% -9.64% 18.05 ms +3.27% -9.03% -5.15%
typeWithTopToolbar 23.29 ms +9.75% -5.93% 22.43 ms +4.32% -4.81% 3.83%
typeContainer 8.1 ms +8.52% -6.67% 7.82 ms +3.71% -11.38% 3.58%
focus 125.5 ms +3.48% -3.3% 119.87 ms +1.69% -5.64% 4.7%
firstFocus 273.43 ms +0% -0% 257.75 ms +0% -0% 6.08%
selectAll 407.73 ms +0.94% -0.39% 420.03 ms +0.62% -3.87% -2.93%
undo 28.95 ms +5.77% -5.11% 27.9 ms +8.53% -1.97% 3.76%
listViewOpen 79.39 ms +4.86% -3.96% 74 ms +7.31% -8.85% 7.28%
inserterOpen 41.21 ms +8.71% -6.89% 41.53 ms +1.57% -6.48% -0.77%
inserterHover 11.77 ms +4.42% -13.42% 11 ms +24% -4.73% 7%
inserterSearch 7.93 ms +7.82% -6.05% 7.55 ms +3.31% -3.84% 5.03%
loadPatterns 619.56 ms +9.64% -4.22% 619.09 ms +5.49% -2.85% 0.08%
wpTotal 474.58 ms +3.85% -8.97% 477.63 ms +2.64% -0.85% -0.64%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 863c723 trunk % Change
serverResponse 325.89 ms +1.99% -9.1% 324.98 ms +1.18% -7.29% 0.28%
firstPaint 387.53 ms +1.29% -1.57% 364.45 ms +5.69% -4.65% 6.33%
domContentLoaded 688.33 ms +0.96% -1.09% 688.22 ms +1.97% -0.62% 0.02%
loaded 689.1 ms +0.98% -1.06% 689.1 ms +1.97% -0.62% 0%
firstContentfulPaint 390.21 ms +6.72% -1.6% 391.59 ms +1.8% -1.65% -0.35%
firstBlock 2103.61 ms +2.18% -0.44% 2078.64 ms +0.84% -0.43% 1.2%
type 16.66 ms +2.88% -14.59% 16.06 ms +7.72% -4.79% 3.74%
navigate 98.61 ms +7.46% -7.16% 100.05 ms +9.69% -4.68% -1.44%
loadPatterns 1201.93 ms +8.2% -8.54% 1168.92 ms +9.71% -5.93% 2.82%
loadPages 953.14 ms +6.61% -3.6% 941.35 ms +3.82% -3.78% 1.25%
wpTotal 317.3 ms +1.97% -9.28% 316.58 ms +1.21% -7.56% 0.23%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

414e4a6 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.

a navigation superseded by the traversal discharges to idle in /test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts, passed after 1 failed attempt.
SyntaxError: Unexpected token 'o', "not hydrated" is not valid JSON
    at readLog (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:28:14)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:47:24
    at waitForLogLength (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:46:2)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:693:5
does not double up an event React already delivers in /test/e2e/specs/editor/various/editable-root-compat.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/editable-root-compat.spec.js:291:5
does not select blocks in the canvas preview when editing from the sidebar (Site Editor v2) in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('combobox', { name: 'Search or type URL' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('combobox', { name: 'Search or type URL' }) with timeout 5000ms
  - waiting for getByRole('combobox', { name: 'Search or type URL' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:416:47)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:21
should restore an older revision in /test/e2e/specs/editor/various/revisions.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

  Array [
    Object {
      "attributes": Object {
-       "content": "Original content - Updated content - Autosaved",
+       "content": "Original content",
      },
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/revisions.spec.js:146:5
should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-5927f28b-be37-4ae4-84c7-b97c92b2d3a3" data-block="5927f28b-be37-4ae4-84c7-b97c92b2d3a3" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5

414e4a6 Run

@github-actions github-actions Bot added the [Tool] Dependency Extraction Webpack Plugin /packages/dependency-extraction-webpack-plugin label Nov 19, 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

[Tool] Dependency Extraction Webpack Plugin /packages/dependency-extraction-webpack-plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant