Skip to content

fix: expose @wordpress/theme as window.wp.theme - #614

Merged
dcalhoun merged 2 commits into
trunkfrom
fix/expose-wp-theme-global
Sep 2, 2026
Merged

fix: expose @wordpress/theme as window.wp.theme#614
dcalhoun merged 2 commits into
trunkfrom
fix/expose-wp-theme-global

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Sep 2, 2026

Copy link
Copy Markdown
Member

What?

Expose @wordpress/theme as window.wp.theme alongside the other WordPress globals, and add it as a direct dependency.

Why?

Jetpack blocks fail to register in the editor against Jetpack's upcoming 16.2 release, which currently ships on the wordpress.org trunk build that .wp-env.json installs. The web E2E third-party-blocks spec fails as a result.

Jetpack's editor bundle now includes @wordpress/ui 0.21, whose ThemeProvider shim reads window.wp.theme at module-evaluation time and throws when it is missing:

@wordpress/ui: @wordpress/theme must expose `ThemeProvider` or `privateApis.ThemeProvider`.

In wp-admin, WordPress registers the wp-theme script. GutenbergKit populates window.wp itself and did not define theme, and the Jetpack editor-assets endpoint treats wp- handles as core-provided, so nothing else fills the gap.

How?

Import @wordpress/theme in wordpress-globals.js and assign it to window.wp.theme. The installed 0.8.0 exposes privateApis, which the @wordpress/ui shim unlocks as a fallback for ThemeProvider. The package was previously only a transitive dependency via @wordpress/dataviews, so it is now declared directly.

Testing Instructions

  1. Run make wp-env-start.
  2. Run npx playwright test e2e/third-party-blocks.spec.js.
  3. Both tests pass. On trunk they fail with the error above.

Accessibility Testing Instructions

N/A. No UI changes.

Screenshots or screencast

N/A

🤖 Generated with Claude Code

https://claude.ai/code/session_01VnQd7G77gehA2PgnzKvFei

dcalhoun and others added 2 commits September 2, 2026 07:51
The package was only reachable transitively through @wordpress/dataviews,
but the editor now imports it to expose window.wp.theme.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VnQd7G77gehA2PgnzKvFei
Jetpack's editor bundle now includes @wordpress/ui 0.21, whose
ThemeProvider shim reads window.wp.theme at module-evaluation time and
throws when it is missing, so no Jetpack block registers. WordPress
registers the wp-theme script in wp-admin, but GutenbergKit populates
window.wp itself and had no theme entry.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VnQd7G77gehA2PgnzKvFei
@dcalhoun dcalhoun added the [Type] Bug An existing feature does not function as intended label Sep 2, 2026
@wpmobilebot

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/614")

Built from fe48f8d

@dcalhoun
dcalhoun marked this pull request as ready for review September 2, 2026 13:31
@dcalhoun
dcalhoun requested a review from nbradbury September 2, 2026 13:40
@nbradbury

Copy link
Copy Markdown
Contributor

@dcalhoun This looks good and I'll approve it, but Claude had this to say:

package.json:74 — "@wordpress/theme": "^0.8.0" pins the root copy to 0.8.x. The next routine bump of @wordpress/block-editor/@wordpress/editor will pull a @wordpress/ui requiring a later minor; npm will keep 0.8.x hoisted (to satisfy this new direct dep) and nest the newer copy under @wordpress/ui. window.wp.theme then hands plugins a ThemeProvider from a different module instance than the editor’s own UI uses — different ThemeContext, different tokens, no error thrown (private-apis 1.43 permits the same module name to opt in twice). Silent styling divergence.

Suggest a comment next to the dependency noting the range must be kept in lockstep with whatever @wordpress/ui requires.

I'm not sure if that's an actual problem but thought I should mention it.

@nbradbury nbradbury left a comment

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.

:shipit:

@dcalhoun

dcalhoun commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

@nbradbury thanks for sharing. The finding is correct, but it is not new to these changes. The added ^0.8.0 is correct today. I'll address the possibility of version drift and duplication in a separate PR.

@dcalhoun
dcalhoun merged commit 7399a46 into trunk Sep 2, 2026
25 checks passed
@dcalhoun
dcalhoun deleted the fix/expose-wp-theme-global branch September 2, 2026 16:11
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