Skip to content

[bug]: shadcn add rewrites join(" ") to join("") when tailwind.cssVariables is false #9972

@holdenmatt

Description

@holdenmatt

Describe the bug

shadcn add mutates unrelated string literals during install when the target project's components.json has:

"tailwind": {
  "cssVariables": false
}

In my case, this valid code:

const value = parts.join(" ");

was written to disk as:

const value = parts.join("");

I reduced this to a minimal repro in a plain Vite React TypeScript app.

The likely root cause is transformCssVars: it appears to walk all StringLiteral nodes and apply trimming/mapping logic, which incorrectly affects non-class strings like " ".

I believe the fix is to scope that transform to actual class strings (className, cn(...), clsx(...), cva(...), etc.) instead of all string literals. Happy to send a PR if that approach makes sense.

Affected component/components

Not specific to one component. This appears to affect any registry component installed via shadcn add when: tailwind.cssVariables is false, and the source contains a meaningful non-class string literal

How to reproduce

  1. Create a plain Vite React TypeScript app:
cd /tmp
pnpm dlx create-vite@latest shadcn-vite-mini-repro --template react-ts
cd /tmp/shadcn-vite-mini-repro
  1. Add this components.json:
{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "default",
  "rsc": false,
  "tsx": true,
  "tailwind": {
    "config": "",
    "css": "",
    "baseColor": "neutral",
    "cssVariables": false,
    "prefix": ""
  },
  "aliases": {
    "components": "@/components",
    "utils": "@/lib/utils",
    "ui": "@/components/ui",
    "lib": "@/lib",
    "hooks": "@/hooks"
  }
}
  1. Create /tmp/space-bug.json:
{
  "name": "space-bug",
  "type": "registry:component",
  "title": "Space Bug",
  "description": "Minimal repro for string literal trimming",
  "files": [
    {
      "path": "registry/test/components/space-bug.tsx",
      "type": "registry:component",
      "content": "export default function SpaceBug() {\n  const parts = [\"a\", \"b\"];\n  const value = parts.join(\" \");\n  return <div>{value}</div>;\n}\n"
    }
  ]
}
  1. Install it:
pnpm dlx shadcn@latest add /tmp/space-bug.json --yes --overwrite
  1. Inspect the written file.

Expected:

const value = parts.join(" ");

Actual:

const value = parts.join("");

Note: If components.json is changed to "cssVariables": true, the bug no longer reproduces.

Codesandbox/StackBlitz link

I don't have a hosted reproduction, but the local repro above is minimal and verified.

Logs

System Info

- `shadcn`: `4.0.5`
- Node.js: `22.22.0`
- Package manager: `pnpm`
- Project type: plain Vite React TypeScript app
- OS: macOS

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions