Skip to content

fix: align window.wp globals with WordPress script packages - #785

Merged
dcalhoun merged 7 commits into
trunkfrom
fix/align-wp-globals-with-core-scripts
Oct 14, 2026
Merged

dcalhoun merged 7 commits into
trunkfrom
fix/align-wp-globals-with-core-scripts

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

What?

Align window.wp globals with latest WP Admin state. Flag future misalignment with unit tests.

Why?

Ensure the GutenbergKit environment remains aligned with the WP Admin environment after #780, which removed the window.wp.sync global. Misalignment can lead to cryptic errors.

How?

  • Remove window.wp.sync global
  • Add the window.wp.undoManager global
  • Add unit tests to flag future misalignments

Testing Instructions

N/A, no user-facing changes.

Accessibility Testing Instructions

N/A, no user-facing changes.

Screenshots or screencast

N/A, no user-facing changes.


AI-generated details

What: Remove window.wp.sync, expose window.wp.undoManager, and add a unit test that flags window.wp gaps against installed packages flagged wpScript.

Why:

How: The test reads wpScript and wpScriptDefaultExport from each installed @wordpress/*/package.json and the window.wp.X = … assignments in wordpress-globals.js and wordpress-i18n.js. It reads source rather than importing the modules, which Node can't evaluate. It fails when:

  • a flagged package has no global (missing globals break every plugin script that reads them);
  • a global's shape differs from core's (X.default || X for default-export packages, toCommonJS( X ) otherwise);
  • a global has no flagged package (core dropped it, like wp.sync);
  • an exclusion is no longer flagged.

wpScript approximates core's globals; base-styles is the one exclusion (flagged only to build its stylesheet).

Testing: make test-web-unit. Each check was confirmed to fail when its case is introduced: removing undoManager, swapping the tokenList/url shapes, and re-adding wp.sync.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the [Type] Bug An existing feature does not function as intended label Oct 13, 2026
dcalhoun and others added 3 commits October 13, 2026 11:27
WordPress 7.0+ no longer registers the wp-sync script, and Gutenberg
removed the global upstream (WordPress/gutenberg#81999). Core data
bundles the package, so the direct dependency is unnecessary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WP Admin's post editor exposes it, and plugin tooling would externalize
it there if it ever leaves the bundled packages list. Core data and
compose already bundle it, so exposing it costs nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WordPress exposes a window.wp global for each package flagged wpScript,
and a missing one breaks every plugin script that reads it. The
window.wp.theme gap went unnoticed for months until Jetpack adopted it;
this flags such gaps on the dependency bump that introduces them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dcalhoun
dcalhoun force-pushed the fix/align-wp-globals-with-core-scripts branch from 4952a7a to 454fe42 Compare October 13, 2026 15:27
@wpmobilebot

wpmobilebot commented Oct 13, 2026 •

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/785")

Built from 5db1e88

dcalhoun and others added 4 commits October 13, 2026 12:21
A stray file such as .DS_Store in node_modules/@WordPress made the whole
test file fail with ENOTDIR before any test ran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Core exposes the default export of packages flagged
wpScriptDefaultExport and the module namespace of the rest. Wrong
shapes shipped unnoticed for wp.serverSideRender and wp.shortcode from
#209 until #750.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The coverage check only caught missing globals, so the stale wp.sync
global would have passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge the existence and shape checks so a missing global fails once
with a clear message, list packages in one pass, and assert membership
against plain lists for short failure diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dcalhoun
dcalhoun marked this pull request as ready for review October 13, 2026 16:50
@dcalhoun
dcalhoun requested a review from crazytonyli October 13, 2026 16:50
window.wp.serverSideRender = serverSideRender.default || serverSideRender;
window.wp.shortcode = shortcode.default || shortcode;
window.wp.styleEngine = toCommonJS( styleEngine );
window.wp.sync = toCommonJS( sync );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this mean packages that are built with older version WordPress packages won't be able to get wp.sync? Would that cause any issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, but the impact to GBK is very narrow and the breaking change was accepted in upstream Gutenberg core in WordPress/gutenberg#81999. It's expected that plugins bundle @wordpress/sync themselves or access the relevant utility via @wordpress/core-data's Y option added to the provider creator.

Details explained by Claude below:

Only for plugins built with @wordpress/dependency-extraction-webpack-plugin 6.40–6.56 that import @wordpress/sync; builds before Feb 2026 and from 6.57 on bundle their own copy. In practice those are real-time collaboration transports (e.g. Jetpack's, VIP's). Those can't work in GBK anyway, since collaboration only runs when window.__experimentalEnableRealTimeCollaboration is set, which we never do. A script that throws on load doesn't stop the remaining assets from loading.

Upstream accepted the same break: WordPress/gutenberg#81999 lists it as breaking, WP 7.0/7.1 never shipped wp.sync, and Gutenberg 24.2 drops it. On our side, wp.sync was only added in #750 and never shipped in a GBK release, so nothing regresses.

@dcalhoun
dcalhoun requested a review from crazytonyli October 14, 2026 13:48
@dcalhoun
dcalhoun merged commit 2ad8b71 into trunk Oct 14, 2026
24 checks passed
@dcalhoun
dcalhoun deleted the fix/align-wp-globals-with-core-scripts branch October 14, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants