Script Loader: Defer single-page admin init until DOMContentLoaded (Trac #65103)#78136
Conversation
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>
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Flaky tests detected in 674e0d1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25644586654
|
There was a problem hiding this comment.
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 untilDOMContentLoaded(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
mountIdargument to be injected viawp_json_encode()instead of string interpolation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Should we do the same for the other boot mode call (like site editor v2) |
|
Ok, let's merge since we don't have much time left until the 24h code freeze. |
…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>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: a2a354c |
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
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
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
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
|
FYI, adding missing changelog entry for this change in #78807 |
This adapts WordPress/wordpress-develop#11611 to Gutenberg.
See Core-65103.