TL;DR
- The shadcn CLI fills your project’s style into the registry URL, and any base- style gets the Base UI build.
- Only 13 files have a Base UI copy. The Base UI registry is generated from registry.json, so there’s one manifest to edit.
- drift’s own props stay the same on both libraries, so StepperNext still takes asChild on Base UI.
- The component tests run once per library, and a test fails if the Base UI build mentions radix-ui.
On this page
shadcn/ui now offers Base UI styles next to its Radix ones. A project set up with base-nova has no radix-ui in its dependencies, and until October 28 our components would have added it.
Pull request #23 fixed that and closed issue #1, the first one we filed. This post covers how one registry serves both libraries without keeping two copies of every component, and what we did to test both.
One command, two builds
You install a drift-ui component the same way on either library:
npx shadcn add @drift-ui/stepperThe shadcn CLI requests /r/{style}/stepper.json and fills in the style from your components.json. Two rewrites in next.config.ts decide which build that URL serves:
{ source: "/r/:style(base-[^/]+)/:name", destination: "/r/base/:name" },
{ source: "/r/:style/:name", destination: "/r/:name" },Any style starting with base- gets the Base UI build. Everything else, including new-york, gets Radix. You don’t pick a library at install time, because you already picked one when you set up the project.
Which files get a second copy
The registry has 60 items. Only 13 files have a Base UI version, in registry/base/ui. The rest import nothing from Radix, so both builds ship the same file.
| Files | Why they need one |
|---|---|
avatar, badge, button, dialog, label, popover | Primitives built directly on a Radix part |
stepper, filter-menu, color-picker-controls, bulk-action-bar | drift components that import from Radix |
tour, multi-select, mention-textarea | They use PopoverAnchor, and shadcn’s Base UI popover has no anchor |
We left the Radix source in registry/default and didn’t move it to registry/radix. A move would have touched every import in the site and the tests, for no change in what anyone installs.
The Base UI registry is generated
Nobody edits a second manifest. bun run registry:build maps every item in registry.json through one function, writes the result to registry.base.json (which is gitignored) and builds it to public/r/base.
export function toBaseUiItem(item) {
if (!item.files) return item
const files = item.files.map((file) => ({
...file,
path: baseUiSourcePath(file.path),
}))
const importsBaseUi = files.some((file) =>
readFileSync(file.path, "utf8").includes('from "@base-ui/react/')
)
const dependencies = (item.dependencies ?? []).filter(
(dependency) => dependency !== "radix-ui"
)
return {
...item,
files,
dependencies: importsBaseUi
? ["@base-ui/react", ...dependencies]
: dependencies,
}
}baseUiSourcePath swaps registry/default/ for registry/base/ when that file exists. The dependency list drops radix-ui and adds @base-ui/react only if a file imports it. The Base UI label is a plain <label>, so installing it adds neither package.
One API on both libraries
Base UI composes with a render prop where Radix uses asChild. shadcn’s own Base UI primitives follow Base UI, so a Base UI Button takes render.
drift’s own components keep the same props on both. Code written against <StepperNext asChild> shouldn’t break because the project moved libraries. The Base UI stepper maps asChild onto Base UI’s useRender hook:
function SlotButton({ asChild, children, ...props }) {
return useRender({
defaultTagName: "button",
render: asChild ? children : undefined,
props: asChild ? props : { ...props, children },
})
}The same goes for the rest. TourTarget still wraps its child, FilterMenuItem still takes onSelect, and FilterMenu still takes onCloseAutoFocus. The three anchored components use Popover.Positioner from @base-ui/react directly to place their popups.
Testing both
bun run test runs the UI tests twice, except showcase.test.tsx, which tests the site’s theme showcase and not a registry file. Vitest has a radix project and a base project, and the second one points each import of a file that has a Base UI copy at that copy:
const baseUiAliases = readdirSync("registry/base/ui").map((file) => ({
find: `@/registry/default/ui/${path.parse(file).name}`,
replacement: path.resolve("registry/base/ui", file),
}))
projects: [
{ test: { name: "radix", include: ["tests/**/*.test.{ts,tsx}"] } },
{
resolve: { alias: baseUiAliases },
test: { name: "base", include: ["tests/ui/**/*.test.tsx"] },
},
]bun run typecheck does the same thing for types, with a second tsc pass through tsconfig.base-ui.json. And tests/lib/base-ui-registry.test.ts fails if any file in public/r/base mentions radix-ui, which is the bug we set out to fix.
Four tests failed on Base UI the first time, and none of them were bugs in the components:
| Test | What was different |
|---|---|
| tour and filter-builder | Base UI moves focus one frame after a popup opens, so the tests wait for focus before typing |
| Linear stepper | A disabled Base UI tab uses aria-disabled instead of disabled, so the test now checks that clicking a locked step does nothing |
Button asChild | Skipped on Base UI, where Button takes render |
Two pages per component
Every component has a page for each library, at /components/base/<name> and /components/radix/<name>. Both are generated at build time, so the install note, dependency list and Source tab are already right when the page loads. If you visit /components/<name>, proxy.ts sends you to the library you picked last, which it reads from a cookie, or to Base UI if you haven’t picked one.
What’s still different
The Base UI primitives are ports of drift’s Radix primitives with the same classes. They aren’t copies of shadcn’s Base UI files. That doesn’t matter much in practice, because primitives install by bare name and a Base UI project gets shadcn’s own button and popover. But the preview on our site can look slightly different from what you get.
React Aria was out of scope for the issue and still is.
If your component imports Radix
Before you add a file to registry/base/ui, try the shared route first. Style a trigger with buttonVariants, portal with react-dom, or use a plain element with the right role. A second copy is a second file to keep in step, and review will ask whether you needed it.
If you do need one, give it the same props as the Radix version and run bun run test. The base project picks the new file up on its own. Our good first issues are a smaller place to start.
