Repository navigation
fix(ui): server-safe buttonVariants — fix brands page crash - #230
Merged
Merged
Conversation
The brands page is a Server Component but called buttonVariants() (for the Product Tour link added in #225). buttonVariants was exported from button.tsx, which is a 'use client' module, so the export became a client reference and threw at render: 'Attempted to call buttonVariants() from the server but buttonVariants is on the client.' Move the cva definition into its own non-client module (components/ui/button-variants.ts) and import buttonVariants into the brands page from there. button.tsx re-exports it unchanged, so the 6 existing client callers keep working with no change.
9 of 13 tasks
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.
Problem
Production runtime crash on the brands dashboard page:
brands/page.tsxis a Server Component (export default async function BrandsPage). The Product Tour link added in #225 callsbuttonVariants({ variant: 'outline', size: 'sm' })to style an<a>. ButbuttonVariantswas exported frombutton.tsx, which carries'use client'— so every export from that module (including the purecvahelper) becomes a client reference that cannot be invoked on the server. It threw at render.The 6 other callers of
buttonVariantsare all'use client'components, so they were unaffected — only the server-rendered brands page crashed.Fix
Move the
cvadefinition into its own non-client module,components/ui/button-variants.ts, and importbuttonVariantsinto the brands page from there.button.tsximports it from the new module and re-exports it unchanged, so the existing client callers keep importing from@/components/ui/buttonwith zero change.This is the canonical shadcn split (variants live outside the client component) and prevents the same crash for any future server-side caller.
Files
web/src/components/ui/button-variants.ts— thecvadef, no'use client'web/src/components/ui/button.tsx— imports + re-exportsbuttonVariantsfrom the new module;Buttoncomponent unchangedweb/src/app/[locale]/(dashboard)/dashboard/brands/page.tsx— importsbuttonVariantsfrom@/components/ui/button-variantsVerification
yarn typecheck— cleanyarn lint+prettier --check— cleanyarn build— compiles successfully and prerenders/[locale]/dashboard/brands(the route that crashed before), confirming the Server Component renders