-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Using important: true leads to duplicate rules in output #9205
Comments
In case this raises questions about PostCSS:
|
I don't think this is likely to be related to PostCSS. We do some internal cache clearing stuff on Tailwind Play. Since there's only a single content input source we have it set up to act essentially as if it were a fresh build. |
Thanks Jordan - I don't properly comprehend the flow of:
and thought that the miracle might be PostCSS. Anyway, the duplicates have been annoying us for months and months, so it was nice to get to some level of understanding. |
Yeah I'm not sure why the duplicates some time disappear and sometimes don't but I can absolutely reproduce it in the CLI so I'm taking a look. I've also been able to create a script that makes the rule cache grow significantly which reproduces the slowdown issue. That's a small but significantly helpful data point as well! |
The point at which the duplicate is created in the cache is |
I wouldn’t be surprised if it did used to be the same rule instance but in fixing another bug we’ve introduced a regression (probably by cloning the rule somewhere) that is causing duplicates to appear. Candidates (like |
Alright that duplicate issue is taken care of — as well as the memory leak with the ruleCache. It is append-only be design but we shouldn't be just appending things to it without re-using them. That's definitely a bug. Whoops. Thanks for the repro and analysis. That's super helpful! Could you give the insiders build a test and let us know what you see? |
LGTM. |
This issue supersedes #9203 which was a bit of a false start.
V3.1.18
Tailwind CLI
Node v14.18.1
Chrome
Window 10 (No Docker or WSL)
Command line : npx tailwindcss --output twout.css --watch -i twbase.css
Reproduction URL: https://github.com/willdean/TwRepro1
Describe your issue
When the important option is set to true, modifications to the source file cause TW to emit duplicate rules into the output for each update.
Repro steps:
twout.css
contains just two rules (after the boilerplate):ml-4
selector on the second div becomesml-6
and save the filetwout.css
The output file now contains
i.e. the
.ml-2
rule has been duplicated.This will happen each time a modification to the source file is made - there will be an additional
.ml-2
rule generated.Some commentary:
I have spent some time trying to understand this, and I think there may be two separate problems, though I'm not a JS developer by trade, and I don't really understand TW's architecture, so please forgive me if I'm completely wrong here.
Possible Issue 1 - Each time a file is modified, TW adds duplicates of all the rules related to that specific file to
context.stylesheetCache
. This is nothing to do with whether theimportant
configuration option is set or not. However, this does not normally cause duplication in the output, because the code which later converts the list of rules into css code elides all the duplicates. This may however be a part of the slow-down/leak problem in #7449.Possible Issue 2- The code which converts the rules list into CSS (is this Postcss?) is apparently able to elide duplicate rules, and that normally deals with the duplicates which build-up in the cache. However, this elision features partly breaks (not completely - some rules get repeated 'n' times, whereas some only see one duplicate) when the
important
option is set.If issue 1 is dealt with then issue 2 possibly wouldn't matter. In #9203 I posted some very crude work-around code which stops the duplicates in the cache.
Edit: This issue doesn't seem to repro in https://play.tailwindcss.com/
The text was updated successfully, but these errors were encountered: