Skip to content

Premium Analytics: Serve the bundled widget-primitives over Core's on WP 7.2 - #54834

Merged
adamwoodnz merged 6 commits into
trunkfrom
stats-620-premium-analytics-stats-fails-to-load-on-wp-72
Nov 12, 2026
Merged

adamwoodnz merged 6 commits into
trunkfrom
stats-620-premium-analytics-stats-fails-to-load-on-wp-72

Conversation

@adamwoodnz

@adamwoodnz adamwoodnz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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's wp/7.2 branch, which carries widget-primitives 0.10.0. With no Gutenberg active the polyfill left that registration alone, and wp_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/.
  • Premium Analytics' widgets-toolkit imports useWidgetIdentity (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 a src under wp-includes via WP_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.
  • The Core check runs before the "newest bundled copy wins" comparison between plugin copies, which is otherwise unchanged. Copies released before this check record their bundled version in the shared versions global even where Core had already won the module ID and their own registration was ignored. 0.7.4 bundles widget-primitives 0.11.0, so on WP 7.2 the global says 0.11.0 is served while the page gets Core's 0.10.0, and a later copy comparing 0.11.0 against 0.11.0 would skip the module and leave Core's copy in place. Which plugin's copy loads first would then decide whether the dashboard works.

Screenshots

Both taken on the same site, WordPress 7.2-beta4 with Gutenberg absent, toggling only this PR's change to register_modules().

Before After
Stats v2 on WP 7.2-beta4 without the fix, showing "Something went wrong!" and the missing-export error Stats v2 on WP 7.2-beta4 with the fix, showing the Site traffic dashboard rendering normally

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 bundled widget-primitives now 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_threshold the 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 registered src and acts only on Core's, under wp-includes. A copy from anywhere else keeps first-wins, because the registered version is a cache-busting hash and nothing exposes the package version behind it.

The exposure left is a future Core shipping a newer widget-primitives than 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's wp/7.2 branch still pins 0.10.0 and 7.2 is in feature freeze, so the earliest Core release that could carry useWidgetIdentity is 7.3. STATS-621 tracks bounding the replacement below that release, with force_threshold as register_scripts() already does it, and dropping the module from MODULE_IDS once Jetpack's minimum WordPress version reaches it.

Related product discussion/links

  • STATS-620
  • STATS-621, the follow-up to retire this replacement once Core ships the exports
  • WordPress/gutenberg#85729, which added useWidgetIdentity

Does 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.

  • Open admin.php?page=jetpack-premium-analytics-wp-admin. On trunk it shows "Something went wrong"; with this branch the dashboard loads.
  • Confirm the import map now points at the bundled copy rather than /wp-includes/:
    JSON.parse(document.querySelector('script[type=importmap]').textContent).imports['@wordpress/widget-primitives']
  • Confirm the export arrived: Object.keys(await import('@wordpress/widget-primitives')).includes('useWidgetIdentity')
  • Check a chart takes its accessible name from its widget title, announced as "Chart: <widget title>".
  • Regressions to rule out: on WP 7.1.x the dashboard still loads, and with Gutenberg 24.4.0 or later active it still loads with the import map pointing at Gutenberg's copy.
  • Open one other wp-build dashboard on 7.2, such as My Jetpack or Protect, and confirm it still loads.

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.

  • Core's copy is the one that breaks. 7.2-beta4 registers @wordpress/widget-primitives in wp-includes/assets/script-modules-packages.php, and that bundle exports useWidgetActions and useWidgetHost but not useWidgetIdentity.
  • Before the fix, the import map resolved to /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.
  • After the fix, it resolves to the bundled jetpack_vendor/automattic/jetpack-wp-build-polyfills/build/modules/widget-primitives/index.js, useWidgetIdentity is present, and the dashboard renders in full: traffic chart, Top pages, Top referrers, Devices, with no console errors.
  • The same before/after holds at the registration level, checked directly against WP_Script_Modules on 7.2-beta4 with the change toggled. Re-checked after the src test was added: Core's http://localhost/wp-includes/js/dist/script-modules/widget-primitives/index.js still gives way to the bundled copy, and the dashboard still renders with no console errors.
  • A supported Gutenberg keeps its own copy, now checked live rather than by unit test. Gutenberg 24.4.0 released on 12 November and is the first release carrying widget-primitives 0.11.0. Installed on 7.2-beta5, the registered src is 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, useWidgetIdentity resolves, and a chart is announced as "Chart: Traffic summary", so the export is exercised and not merely present.
  • WordPress 7.1.4 with Gutenberg absent, on an Atomic site running this branch through Jetpack Beta: every Jetpack admin page the site offers loads, 14 of them, with no crash. This is the one path the change alters on 7.1.x, where $replace becomes true and the deregistration runs against a module ID that nothing registered. The import map on the Stats dashboard points at the bundled copy and useWidgetIdentity is present.
  • WordPress 7.1.4 with Gutenberg 24.3.1 active: 13 dashboards load, the import map on the bundled copy throughout, which is the too-old-Gutenberg path behaving as before this change.
  • composer phpunit in projects/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 no method_exists() guard.
  • PHPCS clean on the changed files.

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 file console warning on the Backup and Podcast dashboards. It comes from @automattic/jetpack-config at build time, predates this branch, and is unrelated to script modules; those pages render normally.

🤖 Generated with Claude Code

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.
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the stats-620-premium-analytics-stats-fails-to-load-on-wp-72 branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack stats-620-premium-analytics-stats-fails-to-load-on-wp-72
bin/jetpack-downloader test jetpack-mu-wpcom-plugin stats-620-premium-analytics-stats-fails-to-load-on-wp-72

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 8, 2026
    • Code freeze: December 7, 2026

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.

@jp-launch-control

jp-launch-control Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

No summary data is available for parent commit e647191, so cannot calculate coverage changes. 😴

If that commit is a feature branch rather than a trunk commit, this is expected. Otherwise, this should be updated once coverage for e647191 is available.

Full summary · PHP report · JS report

@adamwoodnz
adamwoodnz marked this pull request as ready for review November 12, 2026 01:30
@adamwoodnz adamwoodnz added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 12, 2026
…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)
@github-actions github-actions Bot added the Docs label Nov 12, 2026
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)
@adamwoodnz

This comment was marked as resolved.

@claude

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)
@adamwoodnz

Copy link
Copy Markdown
Contributor Author

Review cycle summary

Three Codex rounds, then one final review. 9 findings: 6 fixed, 3 declined. Latest head 9b0055f.

Fixed

Finding Commit
The ordering hole: a copy released before the Core check records its bundled version although Core had already won the module ID, so a later copy compared 0.11.0 against 0.11.0 and left Core's copy in place. The Core check now runs before the version comparison, with a test seeding the global alongside a Core registration 1c06c39
Replacement displaced any registration a supported Gutenberg had not made, not just Core's. It now matches Core's src under wp-includes, so an unrelated third-party registration keeps first-wins 9f35521
File header read as though Core always ships widget-primitives 1c06c39
README still described script modules as first-wins with a single Gutenberg exception, and then described the new behaviour in one hard-to-parse clause 23196df, 9f35521, 9b0055f
Package changelog entry described the registration mechanism rather than the fix, and said Core's module "replaced" the bundled one when it only registered first 5e9e0ec, 9b0055f

Declined

method_exists() guard on WP_Script_Modules::get_registered(). Not needed: the method is in the WordPress 7.0 release, checked against the 7.0 tag, and 7.0 is this package's floor.

Matching Core's copy on the parsed path instead of the includes_url() prefix. The filter drift this guards against would need includes_url or site_url to change between Core's registration and priority 20 of the same request. A path match trades that for its own false positive, a plugin serving from a path that contains /wp-includes/js/dist/script-modules/, and the failure mode either way is today's behaviour.

Premium Analytics: prefix on the plugins/stats changelog entry. The repo rule exempts a plugin named for the product the entry is about, and Stats v2 is where users get Premium Analytics, so the prefix would name the package to its own users. The plugins/jetpack entry keeps the prefix, where it does separate one product from the rest.

Verified after the last change

Live WordPress 7.2-beta4 with Gutenberg absent: Core's /wp-includes/js/dist/script-modules/widget-primitives/index.js gives way to the bundled copy, useWidgetIdentity is present, and the Stats dashboard renders with no console errors. 66 tests, 164 assertions green; each new test fails with its own part of the change reverted. PHPCS clean.

@adamwoodnz
adamwoodnz requested a review from a team November 12, 2026 02:45

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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. 🚢

@dognose24

Copy link
Copy Markdown
Contributor

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 dognose24 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.

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.

@adamwoodnz
adamwoodnz merged commit 35083a2 into trunk Nov 12, 2026
186 of 188 checks passed
@adamwoodnz
adamwoodnz deleted the stats-620-premium-analytics-stats-fails-to-load-on-wp-72 branch November 12, 2026 22:21
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] In Progress [Status] Needs Review This PR is ready for review. labels Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs [Package] Wp Build Polyfills [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Stats Data [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Premium Analytics: Stats fails to load on WP 7.2 (core's widget-primitives lacks useWidgetIdentity)

3 participants