Skip to content

Script Loader: Defer single-page admin init until DOMContentLoaded (Trac #65103)#78136

Merged
ellatrix merged 3 commits into
trunkfrom
fix/boot-init-domcontentloaded-race-65103
May 19, 2026
Merged

Script Loader: Defer single-page admin init until DOMContentLoaded (Trac #65103)#78136
ellatrix merged 3 commits into
trunkfrom
fix/boot-init-domcontentloaded-race-65103

Conversation

@westonruter
Copy link
Copy Markdown
Member

This adapts WordPress/wordpress-develop#11611 to Gutenberg.

See Core-65103.

westonruter and others added 2 commits May 10, 2026 17:47
Wrap the dynamic import("@wordpress/boot") emitted by
page-wp-admin.php.template in a DOMContentLoaded guard so the boot
module evaluates only after its classic-script dependencies
(wp-private-apis, wp-components, wp-theme, etc.) have parsed and
executed. Otherwise, a modulepreloaded @wordpress/boot can win the race
against the classic-script-printing pass on fast CDN-fronted hosts in
Chrome, evaluating before wp.theme.privateApis is defined and throwing
"Cannot unlock an undefined object".

Mirrors the corresponding fix made to the generated page-wp-admin.php
files in wordpress-develop. See Trac #65103 and
WordPress/wordpress-develop#11611.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Khokan Sardar <itzmekhokan@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter requested a review from fabiankaegy May 11, 2026 00:51
@westonruter westonruter added Backport to WP 7.0 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta [Type] Bug An existing feature does not function as intended labels May 11, 2026
@github-actions
Copy link
Copy Markdown

Flaky tests detected in 674e0d1.
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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25644586654
📝 Reported issues:

Comment thread packages/wp-build/templates/page-wp-admin.php.template Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the generated WP-Admin single-page initialization for @wordpress/build “pages” to defer the @wordpress/boot dynamic import until DOMContentLoaded, preventing a race where the boot module can evaluate before required classic-script globals are available (Core #65103).

Changes:

  • Defers import( "@wordpress/boot" ) + initSinglePage() execution until DOMContentLoaded (or runs immediately if the DOM is already ready).
  • Refactors the inline init script into a nowdoc-defined JS function and invokes it via sprintf.
  • Switches the mountId argument to be injected via wp_json_encode() instead of string interpolation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/wp-build/templates/page-wp-admin.php.template
Copy link
Copy Markdown
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@youknowriad
Copy link
Copy Markdown
Contributor

Should we do the same for the other boot mode call (like site editor v2)

@ellatrix
Copy link
Copy Markdown
Member

Ok, let's merge since we don't have much time left until the 24h code freeze.

@ellatrix ellatrix merged commit dee6d24 into trunk May 19, 2026
40 checks passed
@ellatrix ellatrix deleted the fix/boot-init-domcontentloaded-race-65103 branch May 19, 2026 12:32
@github-project-automation github-project-automation Bot moved this from 🔎 Needs Review to ✅ Done in WordPress 7.0 Editor Tasks May 19, 2026
@github-actions github-actions Bot added this to the Gutenberg 23.3 milestone May 19, 2026
@github-actions github-actions Bot removed the Backport to WP 7.0 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label May 19, 2026
gutenbergplugin pushed a commit that referenced this pull request May 19, 2026
…rac #65103) (#78136)

Wrap the dynamic import("@wordpress/boot") emitted by
page-wp-admin.php.template in a DOMContentLoaded guard so the boot
module evaluates only after its classic-script dependencies
(wp-private-apis, wp-components, wp-theme, etc.) have parsed and
executed. Otherwise, a modulepreloaded @wordpress/boot can win the race
against the classic-script-printing pass on fast CDN-fronted hosts in
Chrome, evaluating before wp.theme.privateApis is defined and throwing
"Cannot unlock an undefined object".

Mirrors the corresponding fix made to the generated page-wp-admin.php
files in wordpress-develop. See Trac #65103 and
WordPress/wordpress-develop#11611.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Khokan Sardar <itzmekhokan@gmail.com>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
@github-actions github-actions Bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label May 19, 2026
@github-actions
Copy link
Copy Markdown

I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: a2a354c

pento pushed a commit to WordPress/wordpress-develop that referenced this pull request May 19, 2026
This updates the pinned hash from the `gutenberg` from `3a4e8d1418d25da83b70158bcaabf65580690b6b ` to `a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd`.

The following changes are included:

- Bump the github-actions group across 1 directory with 5 updates (WordPress/gutenberg#76530) (WordPress/gutenberg#78298)
- Improve GHCR asset publishing and expand trigger events to include `pull_request` (WordPress/gutenberg#78211) (WordPress/gutenberg#78324)
- I18N: Polyfill script module translations for WordPress < 7.0 (WordPress/gutenberg#77214)
- Fonts: Move admin menu compat from experimental to wordpress-7.0 (WordPress/gutenberg#78227) (WordPress/gutenberg#78370)
- Connectors: Consolidate WP 7.0 compat loading and move from experimental (WordPress/gutenberg#78228) (WordPress/gutenberg#78371)
- RTC: Make sync/collaboration APIs private (WordPress/gutenberg#78267)
- Interactivity API: Fix popover bind hydration (WordPress/gutenberg#77797)
- Script Loader: Defer single-page admin init until DOMContentLoaded (Trac WordPress/gutenberg#65103) (WordPress/gutenberg#78136)

A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/3a4e8d1418d25da83b70158bcaabf65580690b6b…a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd.

Log created with:

git log --reverse --format="- %s" 3a4e8d1418d25da83b70158bcaabf65580690b6b..a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy

See #64595.

git-svn-id: https://develop.svn.wordpress.org/trunk@62380 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request May 19, 2026
This updates the pinned hash from the `gutenberg` from `3a4e8d1418d25da83b70158bcaabf65580690b6b ` to `a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd`.

The following changes are included:

- Bump the github-actions group across 1 directory with 5 updates (WordPress/gutenberg#76530) (WordPress/gutenberg#78298)
- Improve GHCR asset publishing and expand trigger events to include `pull_request` (WordPress/gutenberg#78211) (WordPress/gutenberg#78324)
- I18N: Polyfill script module translations for WordPress < 7.0 (WordPress/gutenberg#77214)
- Fonts: Move admin menu compat from experimental to wordpress-7.0 (WordPress/gutenberg#78227) (WordPress/gutenberg#78370)
- Connectors: Consolidate WP 7.0 compat loading and move from experimental (WordPress/gutenberg#78228) (WordPress/gutenberg#78371)
- RTC: Make sync/collaboration APIs private (WordPress/gutenberg#78267)
- Interactivity API: Fix popover bind hydration (WordPress/gutenberg#77797)
- Script Loader: Defer single-page admin init until DOMContentLoaded (Trac WordPress/gutenberg#65103) (WordPress/gutenberg#78136)

A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/3a4e8d1418d25da83b70158bcaabf65580690b6b…a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd.

Log created with:

git log --reverse --format="- %s" 3a4e8d1418d25da83b70158bcaabf65580690b6b..a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy

See #64595.
Built from https://develop.svn.wordpress.org/trunk@62380


git-svn-id: http://core.svn.wordpress.org/trunk@61661 1a063a9b-81f0-0310-95a4-ce76da25c4cd
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request May 19, 2026
This updates the pinned hash from the `gutenberg` from `3a4e8d1418d25da83b70158bcaabf65580690b6b ` to `a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd`.

The following changes are included:

- Bump the github-actions group across 1 directory with 5 updates (WordPress/gutenberg#76530) (WordPress/gutenberg#78298)
- Improve GHCR asset publishing and expand trigger events to include `pull_request` (WordPress/gutenberg#78211) (WordPress/gutenberg#78324)
- I18N: Polyfill script module translations for WordPress < 7.0 (WordPress/gutenberg#77214)
- Fonts: Move admin menu compat from experimental to wordpress-7.0 (WordPress/gutenberg#78227) (WordPress/gutenberg#78370)
- Connectors: Consolidate WP 7.0 compat loading and move from experimental (WordPress/gutenberg#78228) (WordPress/gutenberg#78371)
- RTC: Make sync/collaboration APIs private (WordPress/gutenberg#78267)
- Interactivity API: Fix popover bind hydration (WordPress/gutenberg#77797)
- Script Loader: Defer single-page admin init until DOMContentLoaded (Trac WordPress/gutenberg#65103) (WordPress/gutenberg#78136)

A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/3a4e8d1418d25da83b70158bcaabf65580690b6b…a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd.

Log created with:

git log --reverse --format="- %s" 3a4e8d1418d25da83b70158bcaabf65580690b6b..a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy

Reviewed by audrasjb.
Merges [62380] to the 7.0 branch.
Fixes #64595.

git-svn-id: https://develop.svn.wordpress.org/branches/7.0@62382 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request May 19, 2026
This updates the pinned hash from the `gutenberg` from `3a4e8d1418d25da83b70158bcaabf65580690b6b ` to `a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd`.

The following changes are included:

- Bump the github-actions group across 1 directory with 5 updates (WordPress/gutenberg#76530) (WordPress/gutenberg#78298)
- Improve GHCR asset publishing and expand trigger events to include `pull_request` (WordPress/gutenberg#78211) (WordPress/gutenberg#78324)
- I18N: Polyfill script module translations for WordPress < 7.0 (WordPress/gutenberg#77214)
- Fonts: Move admin menu compat from experimental to wordpress-7.0 (WordPress/gutenberg#78227) (WordPress/gutenberg#78370)
- Connectors: Consolidate WP 7.0 compat loading and move from experimental (WordPress/gutenberg#78228) (WordPress/gutenberg#78371)
- RTC: Make sync/collaboration APIs private (WordPress/gutenberg#78267)
- Interactivity API: Fix popover bind hydration (WordPress/gutenberg#77797)
- Script Loader: Defer single-page admin init until DOMContentLoaded (Trac WordPress/gutenberg#65103) (WordPress/gutenberg#78136)

A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/3a4e8d1418d25da83b70158bcaabf65580690b6b…a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd.

Log created with:

git log --reverse --format="- %s" 3a4e8d1418d25da83b70158bcaabf65580690b6b..a2a354cf35e5b69c3330d6c1cfd42d8dc2efb9fd | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy

Reviewed by audrasjb.
Merges [62380] to the 7.0 branch.
Fixes #64595.
Built from https://develop.svn.wordpress.org/branches/7.0@62382


git-svn-id: http://core.svn.wordpress.org/branches/7.0@61663 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@arthur791004 arthur791004 added the [Package] Editor /packages/editor label May 25, 2026
@simison
Copy link
Copy Markdown
Member

simison commented May 29, 2026

FYI, adding missing changelog entry for this change in #78807

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

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core [Package] Editor /packages/editor [Package] wp-build /packages/wp-build [Type] Bug An existing feature does not function as intended

Projects

Development

Successfully merging this pull request may close these issues.

7 participants