Skip to content

fix(ui): server-safe buttonVariants — fix brands page crash - #230

Merged
gkhngyk merged 1 commit into
mainfrom
fix/button-variants-server-crash
Jun 11, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/button-variants-server-crash

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

Production runtime crash on the brands dashboard page:

Attempted to call buttonVariants() from the server but buttonVariants is on the client.
  at BrandsHeader (src/app/[locale]/(dashboard)/dashboard/brands/page.tsx:29)

brands/page.tsx is a Server Component (export default async function BrandsPage). The Product Tour link added in #225 calls buttonVariants({ variant: 'outline', size: 'sm' }) to style an <a>. But buttonVariants was exported from button.tsx, which carries 'use client' — so every export from that module (including the pure cva helper) becomes a client reference that cannot be invoked on the server. It threw at render.

The 6 other callers of buttonVariants are all 'use client' components, so they were unaffected — only the server-rendered brands page crashed.

Fix

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 imports it from the new module and re-exports it unchanged, so the existing client callers keep importing from @/components/ui/button with 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

  • new web/src/components/ui/button-variants.ts — the cva def, no 'use client'
  • web/src/components/ui/button.tsx — imports + re-exports buttonVariants from the new module; Button component unchanged
  • web/src/app/[locale]/(dashboard)/dashboard/brands/page.tsx — imports buttonVariants from @/components/ui/button-variants

Verification

  • yarn typecheck — clean
  • yarn lint + prettier --check — clean
  • yarn build — compiles successfully and prerenders /[locale]/dashboard/brands (the route that crashed before), confirming the Server Component renders

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.
@gkhngyk
gkhngyk merged commit bf5979e into main Jun 11, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the fix/button-variants-server-crash branch June 11, 2026 12:53
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.

1 participant