Widget Primitives: Ship as a script module - #80149
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
d1ed2ae to
1b478fe
Compare
|
Size Change: +1.15 kB (+0.01%) Total Size: 7.73 MB 📦 View Changed
|
|
Flaky tests detected in 3b51525. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29519291761
|
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
55c0ec2 to
ee6d599
Compare
3de2eed to
6918da0
Compare
chihsuan
left a comment
There was a problem hiding this comment.
Thanks @retrofox shipping @wordpress/widget-primitives as a script module makes sense to me!
I just have one concern:
build/modules/dashboard-init/index.min.js81.6 kB +81 kB (+13641.92%) 🆘
The compressed-size report shows the init module growing by roughly 81 kB, and it must finish loading before the dashboard can render.
The dashboard route also continues to use much of the same UI stack through widget-dashboard, so some of that code is duplicated.
Would it be possible to consider one of these alternatives?
- Keeping registration in the route. This is simpler and avoids the extra init bundle, but registration remains route-specific and tied to module evaluation.
- Keeping registration in init while lazy-loading
LocationControl. This preserves centralized ownership but adds loading complexity and may not remove all duplication.
Both have tradeoffs, so I’d also be interested in any other approach you have. 🙂
One small documentation follow-up: docs/explanations/architecture/dashboard-widgets.md still says the dashboard route registers its field types, so that description should be updated if the current approach remains.
ship the package as a shared WordPress script module
6918da0 to
3b51525
Compare
|
Thanks, @chihsuan. You were right to flag the init module. I first went down the lazy-loading path, but the weight comes from The init module stayed heavy either way. Moving registration into init only pays off if that code can be deferred, and right now it can't. So I go back to registration, staying on the route where the UI stack is already bundled, so there's no extra init module. This PR is now just the The good thing is that since registration is back in the route, the |
* add wpScriptModuleExports to widget-primitives ship the package as a shared WordPress script module * simplify CHANGELOG entry
What
Ships
@wordpress/widget-primitivesas a WordPress script module (wpScriptModuleExports).Why
The package holds module-scope state: the field type registry is a
Mapin the module. Bundled, the package produces one copy per consumer bundle, so state registered against one copy is invisible to every other, and the package is duplicated across consumers.As a script module it resolves one shared, singly-evaluated instance from the import map. Consumers externalize the package instead of bundling their own copy. The dedup and the single-instance guarantee compound as more consumers appear (route bundles, and independently built widget render modules).
How
packages/widget-primitives/package.json: addwpScriptModuleExports, so wp-build emitsbuild/modules/widget-primitives/and consumers externalize the package to the import map instead of bundling it.Testing
npm run build) and confirmbuild/modules/widget-primitives/exists and is registered inbuild/modules.php.build/routes/dashboard/content.min.asset.php) lists@wordpress/widget-primitivesas a module dependency instead of bundling it.Follow-ups
locationcontrol it registers pulls in the@wordpress/uiautocomplete stack, which isn't a script module yet, so it inlines into the init module (on the critical path). Fix by externalizing@wordpress/uias a shared module, or by loading the control as a separate script module (the@wordpress/latex-to-mathmlpattern). Tracked in #TBD.