Skip to content

Premium Analytics: register widget-modules entity in the init module - #50048

Open
Nikschavan wants to merge 5 commits into
trunkfrom
add/pa-widget-modules-init
Open

Premium Analytics: register widget-modules entity in the init module#50048
Nikschavan wants to merge 5 commits into
trunkfrom
add/pa-widget-modules-init

Conversation

@Nikschavan

@Nikschavan Nikschavan commented Jun 29, 2026

Copy link
Copy Markdown
Member

Proposed changes

Follow-up to retrofox's review note on #49572: move the one-time widgetModule core-data entity registration out of the dashboard route's beforeLoad and into the page init module, so it runs once at app boot instead of on every navigation/preload.

  • packages/init/src/index.ts now registers the widgetModule root entity from init() (which @wordpress/build runs once at boot, before routes render), alongside the existing setupApiFetch() and menu update. The idempotency guard is kept (harmless, in case init() ever re-runs on re-mount/HMR).
  • routes/dashboard/route.ts beforeLoad no longer registers the entity — it's left doing only the connection/sync guards and the date seed. The stale doc-comment paragraph that flagged this as a tracked follow-up is updated to reflect reality.
  • The jetpack/v4 REST namespace literal now has a single source of truth in the data package (DASHBOARD_REST_NAMESPACE in packages/data/src/api/constants.ts, re-exported from the package index). The dashboard route hooks and the init module both import it — so the route folder isn't imported from init, and the literal isn't duplicated.
  • Added @wordpress/core-data, @wordpress/i18n, and @jetpack-premium-analytics/data to packages/init/package.json (matching the versions used elsewhere in the package on trunk). The entity guard/registration calls select( coreStore ).getEntityConfig() and dispatch( coreStore ).addEntities() against the real core-data types directly, no local casts.

This is a behavior-preserving move: the same entity is registered, just once at boot rather than re-checked on every beforeLoad run.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • Build the package: pnpm run build in projects/packages/premium-analytics (under Node 24).
  • Load the Premium Analytics dashboard in wp-admin (?page=jetpack-premium-analytics) on a connected, synced site.
  • Confirm the dashboard widgets still discover and render — the widgetModule entity is now registered at boot via init(), so useWidgetTypes / the stage's getEntityRecords read resolves exactly as before.
  • Navigate around the dashboard (route changes / preloads) and confirm no errors — the registration no longer runs on every beforeLoad.

[Status] Needs Review

@github-actions

github-actions Bot commented Jun 29, 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!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 29, 2026
@jp-launch-control

jp-launch-control Bot commented Jun 29, 2026

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report

Copilot AI 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.

Pull request overview

This PR moves the one-time widgetModule core-data entity registration out of the dashboard route lifecycle and into the Premium Analytics page init module so it runs once at app boot, while also centralizing the jetpack/v4 REST namespace literal in the data package to avoid duplication.

Changes:

  • Register the widgetModule root entity from packages/init during init() (idempotency-guarded).
  • Remove entity registration from the dashboard route beforeLoad, leaving it focused on connection/sync guards and date seeding.
  • Define and export DASHBOARD_REST_NAMESPACE from packages/data and re-export it from the dashboard hooks constants.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
projects/packages/premium-analytics/routes/dashboard/route.ts Removes per-navigation entity registration and updates route doc-comment accordingly.
projects/packages/premium-analytics/routes/dashboard/hooks/constants.ts Re-exports DASHBOARD_REST_NAMESPACE from the data package to avoid duplicating the literal.
projects/packages/premium-analytics/packages/init/src/index.ts Registers the widget-modules entity once at boot from init().
projects/packages/premium-analytics/packages/init/package.json Adds dependencies needed for boot-time registration (core-data, i18n, data).
projects/packages/premium-analytics/packages/data/src/index.ts Re-exports DASHBOARD_REST_NAMESPACE from the data package entrypoint.
projects/packages/premium-analytics/packages/data/src/api/constants.ts Introduces DASHBOARD_REST_NAMESPACE constant as the JS source of truth for jetpack/v4.
projects/packages/premium-analytics/changelog/add-pa-widget-modules-init Adds changelog entry for the behavior-preserving bootstrap move.

Comment thread projects/packages/premium-analytics/changelog/add-pa-widget-modules-init Outdated
@Nikschavan
Nikschavan force-pushed the add/pa-date-range-picker branch from e19a0d0 to 9b543c4 Compare June 30, 2026 03:56
Base automatically changed from add/pa-date-range-picker to trunk June 30, 2026 08:13
@Nikschavan
Nikschavan marked this pull request as draft June 30, 2026 10:37
@Nikschavan
Nikschavan force-pushed the add/pa-widget-modules-init branch from ef956ca to 78c91c3 Compare June 30, 2026 11:19
@Nikschavan
Nikschavan force-pushed the add/pa-widget-modules-init branch from 78c91c3 to 5012ecc Compare June 30, 2026 11:21
@Nikschavan
Nikschavan marked this pull request as ready for review June 30, 2026 11:40
Comment thread projects/packages/premium-analytics/packages/init/src/index.ts
Comment thread projects/packages/premium-analytics/packages/init/src/index.ts Outdated

@retrofox retrofox 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.

I'm having issues with the boot package. It never loads the dashboard init module, so it doesn't register the entity; as a result, all widgets show the uploading state.

Does it work for you?

@Nikschavan
Nikschavan marked this pull request as draft July 1, 2026 06:39
Move the one-time core-data widgetModule entity registration out of the
dashboard route's beforeLoad and into the page init module, so it runs
once at app boot instead of on every navigation/preload.

The jetpack/v4 REST namespace now has a single source of truth in the
data package (DASHBOARD_REST_NAMESPACE), shared by the dashboard route
hooks and the init-module registration.

Addresses retrofox's review note on #49572.
…ce re-export

Drop the boot-once idempotency guard in registerWidgetModulesEntity and
destructure addEntities directly. Remove the DASHBOARD_REST_NAMESPACE
re-export from the dashboard hooks' constants; the two layout hooks now
import it directly from @jetpack-premium-analytics/data, the single source
of truth, matching how the init module and the rest of routes/ consume it.
Re-add the getEntityConfig existence check before addEntities, matching the
upstream @wordpress/dashboard-init pattern so a pre-existing registration
(e.g. from core's dashboard-init) isn't duplicated. Reword the changelog to
drop lifecycle jargon.
…ter trunk merge

The trunk merge brought in routes/post-detail/route.ts (#50096), which imported
DASHBOARD_REST_NAMESPACE from ../dashboard/hooks/constants. This branch moved that
constant's single source of truth into @jetpack-premium-analytics/data, so the old
export no longer exists and esbuild failed. Point the import at the data package,
matching every other importer (init, use-dashboard-layout, use-dashboard-section-layout).
@Nikschavan
Nikschavan force-pushed the add/pa-widget-modules-init branch from 5d5e349 to 0887df2 Compare July 8, 2026 06:21
@Nikschavan

Copy link
Copy Markdown
Member Author

Now that the @wordpress/* dependencies are updated, this PR is ready for a code review!

@Nikschavan
Nikschavan marked this pull request as ready for review July 8, 2026 06:40
@Nikschavan
Nikschavan requested a review from retrofox July 8, 2026 06:40
@retrofox

retrofox commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Now that the @wordpress/* dependencies are updated, this PR is ready for a code review!

It doesn't work when the Gutenberg plugin isn't activated. Although the issue doesn't belong to this PR, I suggest holding off until a fix is in place before landing this one. Working on it.

@retrofox

retrofox commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

#50309

@Nikschavan Nikschavan added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants