Skip to content

Conversation

chocochu
Copy link

  • Changeset: added shadcn@minor with release note “Add unifiedRadixImports flag to shadcn cli and components.json”.

Why

  • Migrating from @radix-ui/react-* to the unified radix-ui package is the preferred path going forward.
  • Today, adding components with the CLI installs @radix-ui/react-* subpackages and emits those imports, forcing you to re-run the Radix migration each time you add components.
  • This feature lets you opt in once (via --unified-radix-imports or components.json) so new components are installed and emitted with radix-ui from the start.
  • Result: no repeated migrations, fewer dependencies, and consistent import style across codebase.

What’s included

  • CLI flags
    • shadcn init --unified-radix-imports: persist preference in components.json.
    • shadcn add --unified-radix-imports: one-off enablement for that add command.
  • Config
    • components.json now supports "unifiedRadixImports": boolean (defaults to false).
    • This is documented in both v4 and www schemas and the CLI docs.
  • Add flow behavior
    • When enabled, registry-resolved JS/TS files are transformed via the existing migrateRadixFile logic:
      • Rewrite imports into a unified import { ... } from "radix-ui".
      • Remove any @radix-ui/react-* dependencies and add radix-ui if needed.
  • Refactor
    • Introduced applyUnifiedRadixImports(tree) inside add-components to DRY out transformation/dependency normalization for both project and workspace add paths.
  • Defaults/templates
    • New projects default to "unifiedRadixImports": false across templates and generated configs.

Technical details

  • Config schema
    • packages/shadcn/src/registry/schema.ts
      • unifiedRadixImports: z.coerce.boolean().default(false).optional()
    • Public schema files
      • apps/v4/public/schema.json: added "unifiedRadixImports": { "type": "boolean" }
      • apps/www/public/schema.json: added "unifiedRadixImports": { "type": "boolean" }
  • CLI additions
    • packages/shadcn/src/commands/init.ts
      • Added --unified-radix-imports option.
      • promptForConfig includes an interactive toggle for unified imports.
      • Passes effective value to addComponents(...) during initial install.
    • packages/shadcn/src/commands/add.ts
      • Added --unified-radix-imports option.
      • Computes effective value from CLI or components.json and forwards it.
  • Add components refactor
    • packages/shadcn/src/utils/add-components.ts
      • New option: unifiedRadixImports?: boolean.
      • New helper: applyUnifiedRadixImports(tree):
        • Applies migrateRadixFile to JS/TS(X) files.
        • Filters out @radix-ui/react-* from dependencies/devDependencies.
        • Adds radix-ui when any @radix-ui/react-* were removed.

Developer docs (API/Interfaces)

  • components.json (new key)
    • unifiedRadixImports (boolean, default: false)
    • When true, any registry files added by the CLI are automatically migrated to radix-ui imports and dependency set updated accordingly.
  • CLI flags
    • --unified-radix-imports
      • On init: persists the setting into components.json.
      • On add: applies the behavior only for that invocation.

Precedence

  • Effective value resolves as:
    • CLI flag --unified-radix-imports (if provided)
    • Else config components.json "unifiedRadixImports"
    • Else false

Testing

  • packages/tests/src/tests/add.test.ts
    • CLI flag path: verifies generated file imports radix-ui and package.json includes radix-ui but no @radix-ui/react-*.
    • Config path: toggling components.json to unifiedRadixImports: true then adding a component yields radix-ui imports.
  • packages/tests/src/tests/init.test.ts
    • Default init writes "unifiedRadixImports": false into components.json.

Docs

  • apps/www/content/docs/cli.mdx and apps/v4/content/docs/(root)/cli.mdx: added the new flag under both init and add.
  • Public schemas updated to include unifiedRadixImports.

Backward compatibility

  • Default behavior unchanged unless the flag/config is set.
  • No legacy aliases retained (feature is new and optional).

Performance and safety

  • Transformations only apply to the registry payload for the current add, not a full codebase walk.
  • Utilize existing function migrateRadixFile which explicitly ignores react-icons and preserves import formatting and semicolon style.
  • Works in both single-repo and workspace setups.

How to enable

  • Persisted via init:
    • shadcn init --unified-radix-imports
  • One-off via add:
    • shadcn add alert-dialog --unified-radix-imports
  • Direct in config:
    • Add "unifiedRadixImports": true to components.json.

TODO

  • Ensure public site schema JSON (non-v4) remains in sync (done in this PR).

- Introduced a new boolean option `unifiedRadixImports` in schema.json and the add command.
- Updated addComponents function to handle unified radix imports.
- Implemented logic to replace @radix-ui/react-* imports with unified radix-ui imports during component addition.
- Added a new optional boolean flag `unifiedRadixImports` to the init command.
- Updated the initialization schema and prompt to include the new option for unified radix-ui imports.
- Ensured the unifiedRadixImports setting is correctly parsed and utilized in the configuration.
- Implemented tests to verify migration to unified radix imports when enabled via CLI flag and in components.json.
- Ensured that the generated component files and package.json reflect the correct imports and dependencies.
Copy link

vercel bot commented Aug 10, 2025

@chocochu is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@shadcn
Copy link
Collaborator

shadcn commented Aug 26, 2025

@chocochu Could this build upon our radix migrate command? https://github.com/shadcn-ui/ui/blob/main/packages/shadcn/src/migrations/migrate-radix.ts

@chocochu
Copy link
Author

@chocochu Could this build upon our radix migrate command? main/packages/shadcn/src/migrations/migrate-radix.ts

yes the feature already uses migrateRadixFile() in this file!

@chocochu
Copy link
Author

@shadcn lmk how ur feeling about this
i can make changes and also update the branch to latest if u agree with the direction

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.

2 participants