Repository navigation
Premium Analytics: Serve the bundled widget-primitives over Core's on WP 7.2 - #54834
Conversation
WordPress 7.2 registers its own @wordpress/widget-primitives script module, built from Gutenberg's wp/7.2 branch, which carries 0.10.0. register_modules() assumed Core never shipped the module, so with no Gutenberg active it left that registration in place and wp_register_script_module() silently discarded the bundled 0.11.0. Premium Analytics imports useWidgetIdentity, added in 0.11.0, at module scope, so the import map handed the dashboard a module without that export and the page blanked with "Something went wrong". WP 7.1.x escaped it by registering no such module, and Gutenberg 24.4.0 or later by winning the registration with a copy new enough to use. A supported Gutenberg still keeps its copy untouched. Only the branch where nothing has vouched for the registration replaces it, so the bundled copy also serves every other wp-build dashboard on 7.2.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Premium Analytics plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Stats Data plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
…changed Address review: README described script-module registration as first-wins with one Gutenberg exception, which stopped being true once the bundled widget-primitives copy started displacing Core's own registration. A consumer reading it would expect Core to win on WordPress 7.2 and be surprised by which copy the import map serves. (Codex P3-1)
Address review: the entry described the module-registration mechanism, so a consumer reading the package CHANGELOG could not tell it was the fix for dashboards that fail to load on WordPress 7.2. The plugin entries already read that way. (Codex P3-2)
Address review: the replacement branch runs whenever no supported Gutenberg is active, so it also deregistered a registration this package knows nothing about. That copy could be newer than the bundled 0.11.0, and a dashboard importing an export only it carries would then fail to load, which is the failure this branch exists to prevent. WP_Script_Modules::get_registered() exposes the registered src, so Core's copy is identifiable by its wp-includes path. Anything else keeps first-wins, since nothing exposes the package version behind it. (Codex P2-1)
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Address review: 0.7.4 writes its package_version into the shared versions global even where Core had already won the module ID and its own registration was ignored. It bundles widget-primitives 0.11.0, so on WordPress 7.2 the global claims 0.11.0 is being served while the page gets Core's 0.10.0. A later copy then took the newest-copy-wins branch, compared 0.11.0 against 0.11.0 and skipped the module, so Core's copy stayed and the dashboard broke. Which plugin's copy loaded first decided it, and no single release can fix that from one side. The Core check now runs before the version comparison, so a recorded version no longer stands against a Core registration. (Claude 1)
Address review: the README sentence carried what is replaced and why in one clause, and the changelog said Core's module replaced the bundled one when it only registered first and kept the ID. (Claude 3)
Review cycle summaryThree Codex rounds, then one final review. 9 findings: 6 fixed, 3 declined. Latest head Fixed
Declined
Matching Core's copy on the parsed path instead of the
Verified after the last changeLive WordPress 7.2-beta4 with Gutenberg absent: Core's |
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for fixing this before 7.2 ships! @adamwoodnz Tested on 7.2-beta5 without Gutenberg: trunk hits the useWidgetIdentity error, this branch loads fine. 🚢
|
Checked on an Atomic site running WordPress 7.2-beta5, Gutenberg plugin deactivated, Jetpack connected, the branch loaded through Jetpack Beta.
So the fix holds on a real Atomic 7.2 site, not only the Docker environment in the description. |
dognose24
left a comment
There was a problem hiding this comment.
Read 9b0055f1984, and walked the arbitration through each case rather than taking the summary table's word for it.
The src-under-includes_url() test is the narrowest thing that distinguishes Core's copy, and the branch is careful to apply it only on the side that matters: a Core registration skips the recorded-version comparison, so a pre-fix copy of this package that recorded 0.11.0 while Core had actually won the ID can no longer block the displacement. A supported Gutenberg still keeps its copy because $record stays false when GUTENBERG_VERSION is set and not too old; a too-old Gutenberg still gets replaced through $gutenberg_too_old regardless of what it or Core registered; and on 7.1, where nothing is registered, the path is unchanged. The third-party copy keeps first-wins, which is the honest answer when nothing exposes the version behind it. WP_Script_Modules::get_registered() is @since 7.0.0, so it is available at Jetpack's floor.
Three tests, one per new branch of the decision, and the "despite a recorded version" one is the one that would have been easy to leave out. Plugin changelogs on the three that ship the dashboard, package entry describes it from the dashboards' side.
Verified on Atomic 7.2-beta5 without Gutenberg as noted above. Approving at 9b0055f1984.
Fixes #54764
Why
On WordPress 7.2 with the Gutenberg plugin inactive, the Premium Analytics dashboard (
admin.php?page=jetpack-premium-analytics-wp-admin) shows "Something went wrong" and nothing else loads. Site owners on 7.2 have no Stats dashboard at all, and 7.2 is due stable on 8 December. The only workaround today is moving the site back to WordPress 7.1.4.Proposed changes
register_modules()assumed Core never ships@wordpress/widget-primitives. WordPress 7.2 registers its own copy, built from Gutenberg'swp/7.2branch, which carries widget-primitives 0.10.0. With no Gutenberg active the polyfill left that registration alone, andwp_register_script_module()ignores a duplicate ID, so the bundled 0.11.0 was discarded and the import map served Core's module from/wp-includes/.widgets-toolkitimportsuseWidgetIdentity(widget-primitives 0.11.0,WordPress/gutenberg#85729) at module scope, so the module failed to instantiate:The requested module '@wordpress/widget-primitives' does not provide an export named 'useWidgetIdentity'.register_modules()now deregisters Core's copy before registering the bundled one, recognising it by asrcunderwp-includesviaWP_Script_Modules::get_registered(). A supported Gutenberg (24.4.0 or later) still keeps its own copy untouched, and a registration from anywhere else still wins by being first.Screenshots
Both taken on the same site, WordPress 7.2-beta4 with Gutenberg absent, toggling only this PR's change to
register_modules().Two things worth a reviewer's attention
The blast radius is every wp-build dashboard, not just Premium Analytics. 19 consumers request all of
MODULE_IDS, so on WP 7.2 the bundledwidget-primitivesnow serves Boost, VideoPress, Forms, Search, Protect, Backup, Social, SEO, My Jetpack and the rest as well. 0.11.0 is a superset of 0.10.0, and every one of those dashboards already takes the bundled copy whenever an older Gutenberg is active, so this is a path they exercise today.The replacement is bounded by who registered the module, not by a WordPress version, unlike the
force_thresholdthe classic-script polyfills (wp-private-apis,wp-rich-text) use. A version floor would be a guess that either expires early or hides this same bug again on the next release, so instead the branch reads the registeredsrcand acts only on Core's, underwp-includes. A copy from anywhere else keeps first-wins, because the registeredversionis a cache-busting hash and nothing exposes the package version behind it.The exposure left is a future Core shipping a newer
widget-primitivesthan we bundle, which we would still downgrade on dashboard pages. The build-time export-contract check keeps the bundled copy ahead of what our own bundles import, so that downgrade cannot cost us an export we use, but it would reach another module on the same page. Gutenberg'swp/7.2branch still pins 0.10.0 and 7.2 is in feature freeze, so the earliest Core release that could carryuseWidgetIdentityis 7.3. STATS-621 tracks bounding the replacement below that release, withforce_thresholdasregister_scripts()already does it, and dropping the module fromMODULE_IDSonce Jetpack's minimum WordPress version reaches it.Related product discussion/links
WordPress/gutenberg#85729, which addeduseWidgetIdentityDoes this pull request change what data or activity we track or use?
No.
Testing instructions
Needs a WordPress 7.2 site (7.2-beta4 or later) with the Gutenberg plugin inactive and Jetpack connected.
admin.php?page=jetpack-premium-analytics-wp-admin. On trunk it shows "Something went wrong"; with this branch the dashboard loads./wp-includes/:JSON.parse(document.querySelector('script[type=importmap]').textContent).imports['@wordpress/widget-primitives']Object.keys(await import('@wordpress/widget-primitives')).includes('useWidgetIdentity')Verified
Exercised on a throwaway monorepo Docker environment forced to WordPress 7.2-beta4, Gutenberg not installed, Jetpack active, the dashboard reached through the Premium Analytics e2e helper's faked connection and Stats fixtures.
@wordpress/widget-primitivesinwp-includes/assets/script-modules-packages.php, and that bundle exportsuseWidgetActionsanduseWidgetHostbut notuseWidgetIdentity./wp-includes/js/dist/script-modules/widget-primitives/index.js?ver=355066e7b5d458a5968d, the same hash the issue reports, and the dashboard showed "Something went wrong!" with the reported error verbatim.jetpack_vendor/automattic/jetpack-wp-build-polyfills/build/modules/widget-primitives/index.js,useWidgetIdentityis present, and the dashboard renders in full: traffic chart, Top pages, Top referrers, Devices, with no console errors.WP_Script_Moduleson 7.2-beta4 with the change toggled. Re-checked after thesrctest was added: Core'shttp://localhost/wp-includes/js/dist/script-modules/widget-primitives/index.jsstill gives way to the bundled copy, and the dashboard still renders with no console errors.srcis identical before and after the polyfills register,wp-content/plugins/gutenberg/build/modules/widget-primitives/index.js, so neither Core's copy nor the bundled one displaces it. The dashboard renders in full,useWidgetIdentityresolves, and a chart is announced as "Chart: Traffic summary", so the export is exercised and not merely present.$replacebecomes true and the deregistration runs against a module ID that nothing registered. The import map on the Stats dashboard points at the bundled copy anduseWidgetIdentityis present.composer phpunitinprojects/packages/wp-build-polyfills: 66 tests, 164 assertions, green. Each of the three new tests fails with its own part of the change reverted: Core's registration served instead of the bundled copy, a third party's displaced, and a recorded 0.11.0 blocking the replacement of Core's copy.WP_Script_Modules::get_registered()is present in the WordPress 7.0 release, which is this package's floor, so it needs nomethod_exists()guard.Not covered: a third-party registration, and two plugin copies at different package versions, both of which exist only in unit tests. Copies at the same version did run together on the 7.1.4 Atomic site, where released Boost 4.8.2 and Social 10.0.0 were active alongside this branch's copy and the module resolved to one of them without breaking the others.
The 7.1.4 runs log a
jetpackConfig is missing in your webpack config fileconsole warning on the Backup and Podcast dashboards. It comes from@automattic/jetpack-configat build time, predates this branch, and is unrelated to script modules; those pages render normally.🤖 Generated with Claude Code