@wordpress/ui: Add runtime validation for Tabs component#75170
@wordpress/ui: Add runtime validation for Tabs component#75170
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. |
|
Size Change: +7 B (0%) Total Size: 2.99 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Pull request overview
Adds development-only runtime validation to @wordpress/ui’s Tabs compound component to catch common misconfigurations (mismatched values and missing Tabs.Root wrapper).
Changes:
- Introduces a dev-only validation context/provider to register
Tab/Panelvalues and emit warnings for mismatches. - Throws (in dev) when
Tabs.Tab,Tabs.Panel, orTabs.Listare rendered outsideTabs.Root. - Adds unit tests and wires in
@wordpress/warning+@wordpress/jest-consolesupport.
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/ui/src/tabs/context.tsx | New validation context/provider + dev/prod hooks for validation behavior. |
| packages/ui/src/tabs/root.tsx | Wraps Tabs.Root with the validation provider. |
| packages/ui/src/tabs/tab.tsx | Registers tab values and enforces Root wrapper in dev. |
| packages/ui/src/tabs/panel.tsx | Registers panel values and enforces Root wrapper in dev. |
| packages/ui/src/tabs/list.tsx | Enforces Root wrapper in dev. |
| packages/ui/src/tabs/test/index.test.tsx | Adds tests for dev-only errors/warnings. |
| packages/ui/package.json | Adds @wordpress/warning dependency and @wordpress/jest-console devDependency. |
| packages/ui/tsconfig.json | Adds TS project reference for ../warning; formatting adjustments. |
| packages/ui/global.d.ts | Includes @wordpress/jest-console global typings. |
| packages/ui/CHANGELOG.md | Documents the new dev-mode validation behavior. |
| package-lock.json | Lockfile updates for added deps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR feedback: Use Map<TabValue, number> instead of Set to correctly track counts of tabs/panels with the same value. This prevents false mismatch warnings when one duplicate unmounts while another is still mounted. Also adds warnings for duplicate Tab/Panel values to help developers catch configuration issues early. Co-authored-by: Cursor <cursoragent@cursor.com>
786a50d to
bd045d9
Compare
What?
Adds development-mode runtime validation to the
Tabscomponent in@wordpress/uito help validate and catch common misconfiguration errors early.Why?
The
Tabscomponent is a compound component whereTabandPanelsubcomponents must be properly paired by theirvalueprop, and all subcomponents must be used within aTabs.Rootwrapper. Currently, misconfigurations fail silently or produce confusing behavior.How?
context.tsx) that tracks registeredTabandPanelvalues and offers validation for subcomponents to make sure they are rendered insideTabs.Rootprocess.env.NODE_ENV !== 'production'). Separate dev and prod implementations to guardantee React Compiler compatibility and better tree-shakeability (as confirmed by the bundle size report)In particular:
Tabs.Rootwill cause an error.Testing Instructions
Tabs.Root), and make sure that warnings/errors are triggered as expected in dev modeNODE_ENV=production npm run storybook:dev) and make sure that the same errors/warnings do not appear