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

Fix polyfill in combination with unused CSS variable removal #17555

Merged
merged 4 commits into from
Apr 7, 2025

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Apr 4, 2025

This PR fixes an issue we noticed while investigating #17553, where the unused CSS variable removal didn't work properly when the theme variable it tried to remove was modified by a polyfill rule.

The way the bookkeeping for the unused CSS variable worked was that it tired to find the declaration inside it's parent after the traversal. However, the color-mix(…) polyfill has since then made changes to the declaration so it can't find it's position correctly anymore and will thus instead delete the last declaration of the node (this caused unrelated CSS variables to be eliminated while the ones with color-mix(…) were unexpectedly kept).

To fix this, we decided to apply the polyfills after any eventual deletions. This also ensures that no @supports query for the variables are created and simplifies the code a bit since all polyfills are now colocated.

Test plan

@philipp-spiess philipp-spiess force-pushed the fix/color-mix-var-removal branch from 352e77f to b93750a Compare April 4, 2025 14:13
@philipp-spiess philipp-spiess marked this pull request as ready for review April 6, 2025 23:58
@philipp-spiess philipp-spiess requested a review from a team as a code owner April 6, 2025 23:58
I believe we used to use `Extract<AstNode, { nodes: AstNode[] }>` to get
all the AstNodes with children. But now that we are also taking its
`'nodes'`, we can simplify this:

```diff
- Extract<AstNode, { nodes: AstNode[] }>['nodes']
- AstNode[]
```
@RobinMalfait RobinMalfait enabled auto-merge (squash) April 7, 2025 09:16
@RobinMalfait RobinMalfait merged commit 811e97d into main Apr 7, 2025
7 checks passed
@RobinMalfait RobinMalfait deleted the fix/color-mix-var-removal branch April 7, 2025 09:18
@dmitrc
Copy link

dmitrc commented Apr 11, 2025

@philipp-spiess, do we have any approximate date for shipping this change (v4.1.4)?

Our codebase is affected by this bug resulting in a number of missing color variables, and so we can't migrate to Tailwind v4.1+ until it's rectified.

Thanks in advance!

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.

3 participants