question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using important: true leads to duplicate rules in output

See original GitHub issue

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:

  1. Start the CLI, using the command line above (or tw.bat on Windows)
  2. Observe that the output file twout.css contains just two rules (after the boilerplate):
.ml-2 {
  margin-left: 0.5rem !important
}
.ml-4 {
  margin-left: 1rem !important
}
  1. Modify the index.html file so that the ml-4 selector on the second div becomes ml-6 and save the file
  2. Verify that the CLI regenerates the output file twout.css

The output file now contains

.ml-2 {
  margin-left: 0.5rem !important
}
.ml-4 {
  margin-left: 1rem !important
}
.ml-2 {
  margin-left: 0.5rem !important
}
.ml-6 {
  margin-left: 1.5rem !important
}

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 the important 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/

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
willdeancommented, Aug 29, 2022

LGTM.

1reaction
thecrypticacecommented, Aug 29, 2022

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Things to Know About Duplicate Rules - Salesforce Help
If the duplicate rule looks for duplicates across objects (for example, contacts that duplicate leads), the duplicate record set includes duplicates on the ......
Read more >
How to Activate Duplicate Rules in Salesforce
Salesforce Duplicate Management allows you to easily deal with duplicates for: Business accounts; Person accounts; Contacts; Leads; Records ...
Read more >
Complete Guide to Salesforce Duplicate Rules
Duplicate Rules : Use Matching Rules to control 'when' and 'where' to find duplicates. · Matching Rules: Identify 'what field' and 'how' to...
Read more >
Manage Duplicate Records in Salesforce
Use duplicate record reports to fine-tune your duplicate and matching rules and share the results of duplicate jobs. Manage Duplicates Using ...
Read more >
Duplicate Management Flashcards - Quizlet
The matching criteria to identify duplicate records. Salesforce comes with three standard matching rules: one for business accounts; one for contacts and leads, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found