tailwindlabs / tailwindcss-jit

MIT License
2.19k stars 40 forks source link

Clone nodes to prevent css-loader from mutating the rule cache #141

Closed thecrypticace closed 3 years ago

thecrypticace commented 3 years ago

Closes #134


We have a rule cache that we reuse — in contrast to normal tailwind which generates fresh rules every run. This is fine when rules are treated as immutable objects. However, aditional postcss plugins may not honor this contract.

For example, if you use css-loader and have url rewriting turned on (and it is by default) then css-loader will mutate the rules it gets from postcss-loader as it has the ability to use the postcss AST directly. This saves on memory but in our case causes an issue because these rule objects point directly to our cache.

Here we combat this by cloning the rules that go directly into the root node.

barnabasmolnar commented 3 years ago

Just gave this a go and it seems to solve https://github.com/tailwindlabs/tailwindcss-jit/issues/62 as well.

adamwathan commented 3 years ago

Legend! Thanks @thecrypticace ❤️