Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: className in CardHeader causes vite minify warnings #6930

Closed
2 tasks done
kapitalistn opened this issue Mar 14, 2025 · 4 comments · Fixed by #6955
Closed
2 tasks done

[bug]: className in CardHeader causes vite minify warnings #6930

kapitalistn opened this issue Mar 14, 2025 · 4 comments · Fixed by #6955
Labels
bug Something isn't working

Comments

@kapitalistn
Copy link

kapitalistn commented Mar 14, 2025

Describe the bug

Got this component via CLI:

function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
	return (
		<div
			data-slot="card-header"
			className={cn(
				"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-[data-slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
				className
			)}
			{...props}
		/>
	)
}

Which causes:

▲ [WARNING] Unexpected ")" [css-syntax-error]

<stdin>:7:6765:
  7 │ ...:grid-cols-\[1fr_auto\]:has(:is()){grid-template-columns:1fr aut...
    ╵                                    ^

After some investigation, exactly this: has-[data-slot=card-action]:grid-cols-[1fr_auto]
causes warnings.

Affected component/components

CardHeader

How to reproduce

  1. Setup React/Vite/TS
  2. Install tailwind using Tailwind v4 Setup Guid
  3. Configure ShadCN.
  4. npx shadcn@latest add card
  5. Use this card somewhere
  6. npm run build

Codesandbox/StackBlitz link

No response

Logs

▲ [WARNING] Unexpected ")" [css-syntax-error]

    <stdin>:7:6765:
      7 │ ...:grid-cols-\[1fr_auto\]:has(:is()){grid-template-columns:1fr aut...
        ╵                                    ^

System Info

{
	"name": "web",
	"private": true,
	"version": "0.0.0",
	"type": "module",
	"scripts": {
		"dev": "vite",
		"build": "tsc -b && vite build --debug",
		"lint": "eslint .",
		"preview": "vite preview"
	},
	"dependencies": {
		"@hookform/resolvers": "^4.1.3",
		"@radix-ui/react-aspect-ratio": "^1.1.2",
		"@radix-ui/react-avatar": "^1.1.3",
		"@radix-ui/react-checkbox": "^1.1.4",
		"@radix-ui/react-dialog": "^1.1.6",
		"@radix-ui/react-label": "^2.1.2",
		"@radix-ui/react-separator": "^1.1.2",
		"@radix-ui/react-slot": "^1.1.2",
		"@radix-ui/react-tooltip": "^1.1.8",
		"@tailwindcss/vite": "^4.0.14",
		"@tanstack/react-router": "^1.114.17",
		"@tanstack/react-table": "^8.21.2",
		"class-variance-authority": "^0.7.1",
		"i18next": "^24.2.3",
		"i18next-browser-languagedetector": "^8.0.4",
		"i18next-http-backend": "^3.0.2",
		"lucide-react": "^0.482.0",
		"react": "^19.0.0",
		"react-dom": "^19.0.0",
		"react-i18next": "^15.4.1",
		"tailwind-merge": "^3.0.2",
		"tailwindcss": "^4.0.14",
		"tailwindcss-animate": "^1.0.7",
		"zod": "^3.24.2"
	},
	"devDependencies": {
		"@eslint/js": "^9.22.0",
		"@tanstack/react-router-devtools": "^1.114.21",
		"@tanstack/router-plugin": "^1.114.17",
		"@types/node": "^22.13.10",
		"@types/react": "^19.0.10",
		"@types/react-dom": "^19.0.4",
		"@vitejs/plugin-react-swc": "^3.8.0",
		"eslint": "^9.22.0",
		"eslint-plugin-react-hooks": "^5.2.0",
		"eslint-plugin-react-refresh": "^0.4.19",
		"globals": "^16.0.0",
		"typescript": "~5.8.2",
		"typescript-eslint": "^8.26.1",
		"vite": "^6.2.2",
		"vite-plugin-svgr": "^4.3.0"
	}
}

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@kapitalistn kapitalistn added the bug Something isn't working label Mar 14, 2025
@oluijks
Copy link

oluijks commented Mar 16, 2025

Have the same warning, the generated css looks like this:

.has-\[data-slot\=card-action\]\:grid-cols-\[1fr_auto\]:has(:is()) {
  grid-template-columns: 1fr auto;
}

For some reason the is() has no selector argument...

@drimov
Copy link

drimov commented Mar 16, 2025

Have the same warning, i came with a little trick but do the work:

//classname for CardHeader
 has-[data-slot=card-action]:grid-cols-\[1fr_auto\]

and vite build without error

@sharasheero
Copy link

Changing

has-[data-slot=card-action]:grid-cols-[1fr_auto]

to

has-data-[slot=card-action]:grid-cols-[1fr_auto] 

(moving the [ after data-) should fix the issue.

@FatahChan
Copy link
Contributor

opened a pr with a fix

@kodiakhq kodiakhq bot closed this as completed in #6955 Mar 20, 2025
kodiakhq bot pushed a commit that referenced this issue Mar 20, 2025
when building using vite and tailwind vite plugin
this following warning appears 


```
rendering chunks (10)...warnings when minifying css:
▲ [WARNING] Unexpected ")" [css-syntax-error]
 grid-cols-\[1fr_auto\]:has(:is()){grid-template-columns:1fr
                                ^
```


this is fixed by complying to tailwind new way of writing data attribute documented  [here](https://tailwindcss.com/docs/hover-focus-and-other-states#data-attributes)

change

```
[data-slot=card-action]:
```
to 

```
data-[slot=card-action]:
```

resolves #6930
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants