Shadcn UI Migration Guide: Transitioning from Radix UI to Base UI #9562
yluiop123
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Shadcn UI Migration Guide: Transitioning from Radix UI to Base UI
This guide documents the key steps and common pitfalls when migrating the Shadcn UI infrastructure from Radix UI to Base UI.
Reference Project
The migration has been largely completed in a Vite environment. You can compare the differences between the two branches:
Repository: [vite-shadcn](https://github.com/yluiop123/vite-shadcn)
Branches: Compare
radix-ui(Legacy) vsmain(Base UI-driven)1. Recommended Migration Order
To minimize debugging difficulty, migrate components based on their dependency depth:
Independent Components: Port atomic components in
src/components/uithat do not depend on other components (e.g., Button, Badge).Composite Components: Port other components within
src/components/uithat have internal dependencies.Secondary Extensions: Port business components built on top of your local UI components.
Native Extensions: Port advanced components that directly extend the original
radix-uiAPIs.Global Regression Testing: Address remaining style deviations and interaction issues.
2. Environment Initialization & Component Updates
There are two ways to introduce Base UI-based components:
Option A: CLI Automation (Recommended)
Update
components.json: Change"style": "new-york"to"style": "base-vega".Execute the overwrite command:
Bash
Option B: Manual Migration
Install dependencies:
pnpm add @base-ui/react.Copy the code from the [Shadcn UI Official Website](https://ui.shadcn.com/) into the corresponding files under
src/components/ui.3. Key API Changes & Pitfalls
Remove
asChildAttributeBase UI handles component rendering differently; you must globally remove the
asChildkeyword from your components.Checkbox
Type Constraint: The
checkedparameter now strictly requires abooleantype.Indeterminate State: Use the new
indeterminateparameter to support partial selection.ToggleGroup
Input Values: The
valueprop now strictly accepts an array.Selection Logic: Use the
multiplefield to explicitly distinguish between single and multiple selection modes.Resizable
The official Base UI Resizable component may trigger errors in certain scenarios.
Form Components: Transition to
FieldIt is recommended to deprecate the existing
Formsystem in favor of the Base UIFieldcomponent. This involves significant logic changes; please refer to the official documentation or the reference project.Styles & Positioning: Replacing Radix Selectors
Search Keywords: Search the project for
radixkeywords (e.g.,data-[state=...].radix-...) within custom component styles.Positioning Engine: Base UI relies on Floating UI for popover logic. Custom components requiring positioning should now utilize the
@floating-ui/reactpackage.4. Cleanup
Once all components are verified and stable, remove the legacy Radix dependencies:
Bash
Beta Was this translation helpful? Give feedback.
All reactions