fix: don't duplicate prefixed rule when selector list was reformatted#1552
Merged
ai merged 1 commit intoJul 16, 2026
Merged
Conversation
The `already()` check compared `before.selector` to the generated
prefixed selector with strict equality. Generated prefixed selectors
always join the comma list with `', '`, so once an existing prefixed
rule had its selector list reformatted (e.g. one selector per line by a
formatter), the comparison failed and Autoprefixer inserted a duplicate
prefixed rule on every run.
Normalize the compared selector with `list.comma(...).join(', ')` so
whitespace differences in the selector list no longer defeat the
duplication check.
Closes postcss#1497
Member
|
Thanks. Released in 10.5.4. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Autoprefixer's output was not idempotent for prefixed rules whose selector list had been reformatted: running it again inserted a duplicate prefixed rule on every pass (#1497).
Root cause
Selector.already()decides whether a prefixed rule already exists by comparingbefore.selectorto the generated prefixed selector with strict equality:Generated prefixed selectors always join the comma list with
', '. Once an existing prefixed rule had its selector list reformatted (for example, one selector per line by a code formatter),before.selectorno longer matched the normalized generated string, the duplication check failed, and a duplicate prefixed rule was added.Fix
Normalize the compared selector with
list.comma(before.selector).join(', ')before the comparison, so purely cosmetic whitespace differences in the selector list no longer defeat the duplication check.Tests
Added a test in
test/selector.test.jscoveringalready()when the existing prefixed rule's selector list was reformatted (one selector per line).Fixes #1497