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 sorting of utilities that share multiple candidates #12173

Merged
merged 2 commits into from
Oct 10, 2023

Conversation

thecrypticace
Copy link
Contributor

Previously, when given a set of utilities or components that have multiple candidates on one of the rules, and sorting multiple sets of rules one after the other, we could cause the sort order of existing rules to be influenced.

For example, given the following components added by a plugin:

addComponents({
  '.x': { color: 'red' },
  '.a': { color: 'red' },

  // Note how this one has both `a` and `y` classes
  '.y .a': { color: 'red' },
})

And the following HTML:

<div class="x y"></div>
<div class="a"></div>

The prettier plugin sorts the first class list x y and returns x y. Then, it sorts a which ALSO has a matching rule containing y. These rules are shared internally and because of this the candidate would be replaced. Thus, when sorting again the order of x y would be flipped because it looked as if y did not have a known sort order (because that rule was now associated with a instead of y).

To work around this, in this PR we're cloning rules when sorting so the state is no longer shared and the order remains consistent.

Fixes tailwindlabs/prettier-plugin-tailwindcss#220
Fixes tailwindlabs/prettier-plugin-tailwindcss#221

@thecrypticace thecrypticace merged commit ad66635 into master Oct 10, 2023
6 checks passed
@thecrypticace thecrypticace deleted the fix/sorting-multiple-candidates-on-one-rule branch October 10, 2023 17:50
thecrypticace added a commit that referenced this pull request Oct 23, 2023
* Fix sorting of utilities that share multiple candidates

* Update changelog
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.

Sorting of transparent colors tracking-tight order is causing issue
1 participant