Skip to content

Widget Primitives: Ship as a script module; register field types at page init#80149

Open
retrofox wants to merge 3 commits into
update/field-type-registryfrom
update/widget-primitives-script-module
Open

Widget Primitives: Ship as a script module; register field types at page init#80149
retrofox wants to merge 3 commits into
update/field-type-registryfrom
update/widget-primitives-script-module

Conversation

@retrofox

Copy link
Copy Markdown
Contributor

Depends on #80148 (branch based on update/field-type-registry; only the last two commits belong to this PR).

What

Exposes @wordpress/widget-primitives as a WordPress script module (wpScriptModuleExports) and moves the dashboard's field type registration from the stage route into packages/dashboard-init, together with the core/location control it registers.

Why

The field type registry introduced in #80148 is module-scope state (a Map), and bundled packages produce one copy per consumer bundle. A registry inside a per-bundle copy is a dead registry for every other bundle: registering from the page init module while the route resolves against its own copy would silently no-op, since unresolved names degrade without warning by design.

Shipping the package as a script module makes the import map resolve one shared, singly-evaluated instance for every consumer. That is what allows the vocabulary to move where it belongs: the page's init module, which already registers the widget-modules discovery entity, runs in both boot modes before anything renders, and covers every route of the page rather than one of them.

Deduplication is the same property seen from the build side: each consumer stops bundling its own copy of the package, and package updates no longer invalidate consumer bundles. With two consumers today (the route bundle and the init module) the byte savings are modest; they compound with every host, route, or page that joins.

Worth noting for review: registering the module does not load it on unrelated admin pages. Static module dependencies are fetched only where the graph imports them, preloaded in parallel and evaluated in dependency order, which is exactly the ordering guarantee registration-before-render relies on. npm consumers are unaffected: the field only adds the WordPress module build; bundling consumers keep bundling.

What this enables next

Not a motivation for this PR, but a direct consequence: with @wordpress/widget-primitives in the import map, independently built widget modules can import registerFieldType and reach the same shared registry. That is the mechanical prerequisite for third-party widgets registering their own field types, tracked as a follow-up in #80148 (the remaining work there is API and policy, not infrastructure).

How

  • packages/widget-primitives/package.json: add wpScriptModuleExports, so wp-build emits build/modules/widget-primitives/ and consumers externalize the package to the import map instead of bundling it.
  • packages/dashboard-init: init() calls registerDashboardFieldTypes() before registering the discovery entity; the field type vocabulary (src/field-types/) and the core/location control (LocationControl, LocationPicker) move here from routes/dashboard/.
  • routes/dashboard: stage.tsx drops the module-scope registration; @wordpress/dataviews, @wordpress/icons, and @wordpress/ui move from the route's dependencies to dashboard-init's.
  • packages/dashboard-init/tsconfig.json: new, with references for every @wordpress dependency, wired into the root tsconfig.json.

Testing

  1. Run npm run build (or npm start) and open the dashboard with the gutenberg-dashboard-widgets experiment enabled.
  2. The events widget behaves exactly as on Widget Primitives: Add a field type registry for widget attributes #80148: the location control renders inline in the widget toolbar and in the settings drawer.
  3. Confirm build/modules/widget-primitives/ exists and is registered (build/modules.php).
  4. Confirm the dashboard route asset (build/routes/dashboard/content.min.asset.php) lists @wordpress/widget-primitives as a static module dependency instead of bundling it, and that the dashboard-init module asset does too.

Follow-ups

  • Third-party field type registration through the module surface (API and policy discussion, tracked in Widget Primitives: Add a field type registry for widget attributes #80148).
  • Evaluate the same treatment for @wordpress/dataviews, where deduplication is the primary motivation (it ships today inside the route bundle and inside every widget that renders with DataViews).

@retrofox retrofox self-assigned this Jul 12, 2026
@github-actions

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: retrofox <retrofox@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@retrofox retrofox force-pushed the update/widget-primitives-script-module branch from 1ca4874 to d1ed2ae Compare July 12, 2026 22:17
@retrofox retrofox force-pushed the update/widget-primitives-script-module branch from d1ed2ae to 1b478fe Compare July 12, 2026 22:23
@github-actions

Copy link
Copy Markdown

Size Change: +55.9 kB (+0.73%)

Total Size: 7.76 MB

📦 View Changed
Filename Size Change
build/modules/block-library/playlist/view.min.js 15.2 kB -219 B (-1.42%)
build/modules/boot/index.min.js 51 kB +124 B (+0.24%)
build/modules/connectors/index.min.js 2.06 kB -394 B (-16.04%) 👏
build/modules/content-types/index.min.js 161 kB -1.88 kB (-1.15%)
build/modules/dashboard-init/index.min.js 81.6 kB +81 kB (+13639.9%) 🆘
build/modules/vips/worker.min.js 3.69 MB -11 B (0%)
build/modules/widget-primitives/index.min.js 1.15 kB +1.15 kB (new file) 🆕
build/scripts/block-directory/index.min.js 44.1 kB -13 B (-0.03%)
build/scripts/block-editor/index.min.js 417 kB -1.7 kB (-0.41%)
build/scripts/block-library/index.min.js 333 kB -13.9 kB (-4.02%)
build/scripts/components/index.min.js 270 kB -1.3 kB (-0.48%)
build/scripts/compose/index.min.js 11.7 kB +24 B (+0.21%)
build/scripts/edit-post/index.min.js 52.2 kB +183 B (+0.35%)
build/scripts/edit-site/index.min.js 300 kB -1.81 kB (-0.6%)
build/scripts/editor/index.min.js 494 kB -1.18 kB (-0.24%)
build/scripts/format-library/index.min.js 29.6 kB -33 B (-0.11%)
build/scripts/media-utils/index.min.js 118 kB -2.03 kB (-1.69%)
build/scripts/rich-text/index.min.js 14.4 kB -87 B (-0.6%)
build/scripts/upload-media/index.min.js 14.4 kB -672 B (-4.46%)
build/styles/block-editor/content-rtl.css 5.66 kB +10 B (+0.18%)
build/styles/block-editor/content.css 5.67 kB +10 B (+0.18%)
build/styles/block-editor/style-rtl.css 19.2 kB -68 B (-0.35%)
build/styles/block-editor/style-rtl.min.css 16.3 kB -56 B (-0.34%)
build/styles/block-editor/style.css 19.2 kB -69 B (-0.36%)
build/styles/block-editor/style.min.css 16.3 kB -59 B (-0.36%)
build/styles/block-library/editor-rtl.css 12.7 kB -54 B (-0.42%)
build/styles/block-library/editor-rtl.min.css 10.3 kB -52 B (-0.5%)
build/styles/block-library/editor.css 12.7 kB -52 B (-0.41%)
build/styles/block-library/editor.min.css 10.3 kB -51 B (-0.49%)
build/styles/block-library/icon/editor-rtl.css 776 B -636 B (-45.04%) 🎉
build/styles/block-library/icon/editor-rtl.min.css 377 B -92 B (-19.62%) 🎉
build/styles/block-library/icon/editor.css 776 B -636 B (-45.04%) 🎉
build/styles/block-library/icon/editor.min.css 377 B -92 B (-19.62%) 🎉
build/styles/block-library/navigation/editor-rtl.css 3.38 kB +9 B (+0.27%)
build/styles/block-library/navigation/editor-rtl.min.css 2.28 kB +9 B (+0.4%)
build/styles/block-library/navigation/editor.css 3.39 kB +9 B (+0.27%)
build/styles/block-library/navigation/editor.min.css 2.28 kB +10 B (+0.44%)
build/styles/block-library/playlist/style-rtl.css 1.99 kB -18 B (-0.89%)
build/styles/block-library/playlist/style-rtl.min.css 1.91 kB -19 B (-0.99%)
build/styles/block-library/playlist/style.css 2 kB -18 B (-0.89%)
build/styles/block-library/playlist/style.min.css 1.91 kB -18 B (-0.93%)
build/styles/block-library/style-rtl.css 22.1 kB -20 B (-0.09%)
build/styles/block-library/style-rtl.min.css 18.6 kB -16 B (-0.09%)
build/styles/block-library/style.css 22.3 kB -17 B (-0.08%)
build/styles/block-library/style.min.css 18.6 kB -15 B (-0.08%)
build/styles/components/style-rtl.css 18.1 kB +11 B (+0.06%)
build/styles/components/style-rtl.min.css 15 kB +19 B (+0.13%)
build/styles/components/style.css 18.2 kB +9 B (+0.05%)
build/styles/components/style.min.css 15 kB +19 B (+0.13%)
build/styles/edit-post/style-rtl.css 3.3 kB +7 B (+0.21%)
build/styles/edit-post/style-rtl.min.css 1.94 kB +5 B (+0.26%)
build/styles/edit-post/style.css 3.3 kB +6 B (+0.18%)
build/styles/edit-post/style.min.css 1.95 kB +6 B (+0.31%)
build/styles/edit-site/style-rtl.css 21.3 kB -64 B (-0.3%)
build/styles/edit-site/style-rtl.min.css 17.4 kB -66 B (-0.38%)
build/styles/edit-site/style.css 21.3 kB -61 B (-0.29%)
build/styles/edit-site/style.min.css 17.4 kB -66 B (-0.38%)
build/styles/editor/style-rtl.css 30.9 kB -12 B (-0.04%)
build/styles/editor/style-rtl.min.css 26.3 kB -18 B (-0.07%)
build/styles/editor/style.css 31 kB -1 B (0%)
build/styles/editor/style.min.css 26.2 kB -19 B (-0.07%)
build/styles/theme/design-tokens-rtl.css 3.38 kB +326 B (+10.69%) ⚠️
build/styles/theme/design-tokens-rtl.min.css 1.62 kB +115 B (+7.65%) 🔍
build/styles/theme/design-tokens.css 3.38 kB +326 B (+10.69%) ⚠️
build/styles/theme/design-tokens.min.css 1.62 kB +115 B (+7.65%) 🔍
build/styles/widgets/style-rtl.css 2.15 kB +2 B (+0.09%)
build/styles/widgets/style-rtl.min.css 1.16 kB +1 B (+0.09%)
build/styles/widgets/style.css 2.15 kB +2 B (+0.09%)
build/styles/widgets/style.min.css 1.17 kB +3 B (+0.26%)

compressed-size-action

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 1b478fe.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29211442980
📝 Reported issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant