Fix sorting of utilities that share multiple candidates #12173
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
And the following HTML:
The prettier plugin sorts the first class list
x y
and returnsx y
. Then, it sortsa
which ALSO has a matching rule containingy
. These rules are shared internally and because of this the candidate would be replaced. Thus, when sorting again the order ofx y
would be flipped because it looked as ify
did not have a known sort order (because that rule was now associated witha
instead ofy
).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