Fix: Preserve 'use client' directive in universal registry items #8798
+132
−22
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.