Skip to content

Fix: Preserve 'use client' directive in universal registry items#8798

Merged
shadcn merged 3 commits intoshadcn-ui:mainfrom
VeiaG:fix-cli-universal-item-rsc
Jan 17, 2026
Merged

Fix: Preserve 'use client' directive in universal registry items#8798
shadcn merged 3 commits intoshadcn-ui:mainfrom
VeiaG:fix-cli-universal-item-rsc

Conversation

@VeiaG
Copy link
Copy Markdown
Contributor

@VeiaG VeiaG commented Nov 13, 2025

Fixes #8432

Problem

Universal registry items (registry:file and registry:item) are designed to be framework-agnostic components that can be installed without running shadcn init or having a components.json file. These items should preserve their original content as-is.

However, the transformRsc transformer was incorrectly removing 'use client' directives from universal item files when config.rsc was false or undefined. This broke client-side functionality in universal items that require React hooks or browser APIs.

Why this happens:

  1. Universal items can be installed without project setup
  2. When no config exists or rsc is false by default, the RSC transformer runs
  3. The transformer removes 'use client' from ALL files, including universal items
  4. This breaks the original functionality of universal items

Solution

Skip all transformers for universal registry items (registry:file and registry:item types) to preserve their original content, similar to how .env files are handled.

Universal items are meant to be copied exactly as-is from the registry, so they should bypass:

  • RSC transformer
  • Import transformer
  • CSS variables transformer
  • Tailwind prefix transformer
  • Icon transformer
  • Next.js middleware transformer

Regular shadcn components (registry:ui, registry:lib, etc.) continue to have transformers applied as expected.

Changes

Modified Files

packages/shadcn/src/utils/updaters/update-files.ts

  • Added check to identify universal item files before applying transformers
  • Skip all transformers for registry:file and registry:item types
  • Preserve original content including 'use client' directives

packages/shadcn/test/utils/updaters/update-files.test.ts

  • Added test: verify 'use client' is preserved in registry:file items
  • Added test: verify 'use client' is preserved in registry:item items
  • Added test: verify 'use client' is still removed from regular components when rsc: false

Testing

The fix includes comprehensive tests to ensure:

  1. ✅ Universal items (registry:file) preserve 'use client' directives
  2. ✅ Universal items (registry:item) preserve 'use client' directives
  3. ✅ Regular components still have transformers applied correctly
  4. ✅ Existing functionality for non-universal items remains unchanged

Impact

  • Universal items: Now work correctly without project initialization
  • Regular components: No change in behavior
  • Backward compatibility: Fully maintained

This ensures universal items work as intended - as standalone, framework-agnostic components that can be copied and used immediately without any transformations.

Universal items (registry:file and registry:item) are framework-agnostic
components that can be installed without shadcn project initialization.
However, the RSC transformer was incorrectly removing 'use client'
directives from these files when config.rsc was false/undefined, breaking
client-side functionality.

This fix ensures transformers are skipped for universal items, preserving
their original content including 'use client' directives, while regular
shadcn components continue to have transformers applied as expected.

Changes:
- Skip all transformers for registry:file and registry:item types
- Add tests to verify 'use client' preservation in universal items
- Ensure regular components still have transformers applied

Fixes issue where universal items would lose 'use client' directives when
copied without a full shadcn project setup.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Nov 13, 2025

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

A member of the Team first needs to authorize it.

@VeiaG
Copy link
Copy Markdown
Contributor Author

VeiaG commented Nov 20, 2025

Gentle ping — let me know if I can do anything to help move this PR forward )

# Conflicts:
#	packages/shadcn/src/utils/updaters/update-files.ts
Copy link
Copy Markdown
Collaborator

@shadcn shadcn left a comment

Choose a reason for hiding this comment

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

Thank you.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jan 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
ui Ready Ready Preview, Comment Jan 17, 2026 8:59am

Request Review

@shadcn shadcn merged commit 2acaf95 into shadcn-ui:main Jan 17, 2026
8 checks passed
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.

[bug]: CLI Registry universal items still removes 'use client' from tsx files

2 participants