ant-design / ant-design/cssinjs

Layer dependencies break utility css solutions (like tailwindcss)

Open
#240 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
287
Forks
80
PR merge metrics
No merged PRs in 30d

Description

Related: #233 ant-design/x#1588 ant-design/x#559 ant-design/ant-design#56015

Currently, if a layer has dependencies, cssinjs will prepend a `@layers deps..., layer.name` at the front of header, effectively setting all of these layers the lowest priority.

https://github.com/ant-design/cssinjs/blob/e964b756104ea1763649304202b19aaa3e561553/src/hooks/useStyleRegister.tsx#L485-L493

When importing a css in code with bundlers like vite, the css is always placed after the very first `@layers` statement, therefore having higher priorities.

This has caused multiple issues when used together with utility css solutions like tailwindcss. See the related issues above, which illustrate lots of problems caused by this issue.

For example, it breaks [the intended behavior](https://ant.design/docs/react/compatible-style-cn#tailwindcss-%E6%8E%92%E5%B8%83-layer) of Ant Design, when used together with Ant Design X. Minimal reproducible project [here](https://github.com/ZeroAurora/antd-layer-reproduce). To put it simple: **If you are developing with antd + antd/x + tailwindcss, it just breaks.**

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/hooks/useStyleRegister.tsx around lines 485-493 and reproduce the layer ordering problem with the linked antd-layer-reproduce project. Compare the generated @layer statement with CSS imported by Vite and the related issues. Done means the intended Ant Design, Ant Design X, and Tailwind CSS layer behavior is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
tailwindcss, typescript, vite
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.