Skip to content

Widget Primitives: extract into @wordpress/widget-primitives#79134

Merged
retrofox merged 80 commits into
trunkfrom
add/widget-primitives-package
Jun 16, 2026
Merged

Widget Primitives: extract into @wordpress/widget-primitives#79134
retrofox merged 80 commits into
trunkfrom
add/widget-primitives-package

Conversation

@retrofox

@retrofox retrofox commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What?

Moves the widget toolkit from routes/dashboard/widget-primitives/ into a standalone package, packages/widget-primitives/, published as @wordpress/widget-primitives at 0.1.0-prerelease (experimental). No behavior changes.

The package is the single source of truth for the widget contract:

  • Contract types: WidgetType, WidgetName, WidgetIcon, WidgetRenderProps, ResolveWidgetModule.
  • Discovery: the useWidgetTypes() hook.
  • Rendering: the <WidgetRender> host entry point.

Also adds docs/explanations/architecture/dashboard-widgets.md, explaining how the pieces of the widget system fit together (authoring convention, build pipeline, server registry, client contract, hosts).

Why?

The widget contract is a public boundary: authors write against it, hosts render through it.

While it lives in routes/dashboard/, it stays private: no external project can consume it.
Moving it to a public, top-level package makes it consumable on its own.

How?

  • git mv of the tree into packages/widget-primitives/src/, preserving history; the sources are unchanged.
  • Publish-ready package.json (exports/types pointing at the build artifacts, wpScript: false, publishConfig.access: public, peer dep on react) and a tsconfig.json with its project references.
  • WidgetIcon stays a plain SVG ReactElement, with no @wordpress/ui dependency: any host can define and consume its own icons.
  • The dashboard route now consumes the package: a file: workspace dependency, imports pointing at @wordpress/widget-primitives, its exclude in routes/dashboard/tsconfig.json removed, and a reference in the root tsconfig.json.
  • README aligned to the standard package pattern and an initial CHANGELOG.md; WidgetRender stories, with an Introduction page that renders the architecture document.

Testing

  1. Run the unit tests covering the dashboard route and the widget contract (dashboard rendering, inserter, commands, settings, widget creation):
npm run test:unit routes/dashboard
image
  1. Storybook
  • Widget Primitives/Introduction renders the architecture document; under Widget Primitives/WidgetRender, Default shows the render contract.
  • WithSettings edits the widget through a DataForm mounted from the type's declarative attributes (Field[]).
  • WithHostChrome frames the widget in host chrome (striped) around the widget render (solid).
npm run storybook:dev
Screen.Recording.2026-06-12.at.10.19.26.AM.mov
  1. Manual check through the dashboard route. Enable the gutenberg-dashboard-widgets experiment and load /wp-admin/:

  2. Confirm that widgets render, that the inserter lists the registered widget types, and that widget settings open.
    All widget-type data now flows through @wordpress/widget-primitives.

  3. Disable the gutenberg-dashboard-widgets experiment and confirm wp-admin still works as before: the package is consumed only behind the experiment, so the default admin must be unaffected.

Follow-ups

  • Extract the dashboard rendering engine (widget-dashboard) into its own package, depending on this one.
  • Decide per package whether to expose the externalized ES module.
  • After the first npm sync, verify @wordpress/[email protected] installs and resolves outside the monorepo.

retrofox added 30 commits May 24, 2026 14:57
parametric 0-9 glyphs with per-stroke gradients, all WPDS tokens
@retrofox retrofox requested review from adamwoodnz, chihsuan and louwie17 and removed request for fabiankaegy June 12, 2026 01:29
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 8.58 MB

compressed-size-action

@retrofox retrofox requested a review from nerrad June 12, 2026 01:54
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Flaky tests detected in 21d2816.
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/27568263274
📝 Reported issues:

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

Nice, clean extraction! @retrofox Verified that widgets still render and wp-admin still works.

Just flagged a small thing in the package README's "How discovery works" section. Other than that, LGTM.

Comment thread packages/widget-primitives/README.md Outdated
1. **Server (PHP).** `WP_Widget_Type_Registry` is hydrated at `init` from the
build manifest. One entry per widget folder under `widgets/`.
2. **REST endpoint.** `/wp/v2/widget-modules` exposes the registry. Each record
returns `{ name, render_module, widget_module }`.

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.

I noticed that the SVG diagram show { name, render_module, widget_module, presentation }. Should we aligning step 2 and step 4 to include presentation?

@retrofox retrofox Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, we should. Thanks!!!

@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 <[email protected]>
Co-authored-by: chihsuan <[email protected]>

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

retrofox added 2 commits June 12, 2026 16:46
add react-dom peer and storybook devDependencies
the REST record carries it and the hook merge prefers it
@retrofox retrofox changed the title Widget Primitives: extract into @wordpress/widget-primitives Widget Primitives: extract into @wordpress/widget-primitives Jun 12, 2026
@retrofox retrofox merged commit e733a66 into trunk Jun 16, 2026
49 of 50 checks passed
@retrofox retrofox deleted the add/widget-primitives-package branch June 16, 2026 16:00
@github-actions github-actions Bot added this to the Gutenberg 23.5 milestone Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Dashboard WordPress admin dashboard, widget framework, and layout customization npm Packages Related to npm packages [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants