Skip to content

fix: don't duplicate prefixed rule when selector list was reformatted#1552

Merged
ai merged 1 commit into
postcss:mainfrom
xianjianlf2:fix/duplicate-prefixed-selector-1497
Jul 16, 2026
Merged

fix: don't duplicate prefixed rule when selector list was reformatted#1552
ai merged 1 commit into
postcss:mainfrom
xianjianlf2:fix/duplicate-prefixed-selector-1497

Conversation

@xianjianlf2

Copy link
Copy Markdown
Contributor

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 comparing before.selector to the generated prefixed selector with strict equality:

if (before.selector === prefixed) {

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.selector no 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.js covering already() when the existing prefixed rule's selector list was reformatted (one selector per line).

Fixes #1497

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
@ai
ai merged commit fd31eb3 into postcss:main Jul 16, 2026
9 checks passed
@ai

ai commented Jul 16, 2026

Copy link
Copy Markdown
Member

Thanks. Released in 10.5.4.

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.

Rules duplicate when moz-placeholder prefix added

2 participants