Fix: Preserve 'use client' directive in universal registry items#8798
Merged
shadcn merged 3 commits intoshadcn-ui:mainfrom Jan 17, 2026
Merged
Fix: Preserve 'use client' directive in universal registry items#8798shadcn merged 3 commits intoshadcn-ui:mainfrom
shadcn merged 3 commits intoshadcn-ui:mainfrom
Conversation
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.
Contributor
|
@VeiaG is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
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
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8432
Problem
Universal registry items (
registry:fileandregistry:item) are designed to be framework-agnostic components that can be installed without runningshadcn initor having acomponents.jsonfile. These items should preserve their original content as-is.However, the
transformRsctransformer was incorrectly removing'use client'directives from universal item files whenconfig.rscwasfalseorundefined. This broke client-side functionality in universal items that require React hooks or browser APIs.Why this happens:
rscisfalseby default, the RSC transformer runs'use client'from ALL files, including universal itemsSolution
Skip all transformers for universal registry items (
registry:fileandregistry:itemtypes) to preserve their original content, similar to how.envfiles are handled.Universal items are meant to be copied exactly as-is from the registry, so they should bypass:
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.tsregistry:fileandregistry:itemtypes'use client'directivespackages/shadcn/test/utils/updaters/update-files.test.ts'use client'is preserved inregistry:fileitems'use client'is preserved inregistry:itemitems'use client'is still removed from regular components whenrsc: falseTesting
The fix includes comprehensive tests to ensure:
registry:file) preserve'use client'directivesregistry:item) preserve'use client'directivesImpact
This ensures universal items work as intended - as standalone, framework-agnostic components that can be copied and used immediately without any transformations.