Skip to content

Fix declaration order after @at-root - #181

Merged
ai merged 1 commit into
postcss:mainfrom
wozhenbang2004:fix/at-root-declaration-order
Nov 7, 2026
Merged

ai merged 1 commit into
postcss:mainfrom
wozhenbang2004:fix/at-root-declaration-order

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

Declarations after @at-root are currently emitted in the original parent rule, ahead of the rule that @at-root hoists. If both rules set the same property on the same selector, this can reverse the cascade.

Reuse the existing declaration handling for hoisted rules so later declarations are emitted after @at-root. Both shorthand and block regressions fail on the unmodified implementation. pnpm test passes all 81 tests with the fix.

@ai

ai commented Nov 5, 2026

Copy link
Copy Markdown
Member

Can you show input, before and after exampes?

@wozhenbang2004

Copy link
Copy Markdown
Contributor Author

For example, this input:

a {
  color: red;
  @at-root a { color: blue; }
  color: green;
}

Before:

a { color: red; color: green; }
a { color: blue; }

After:

a { color: red; }
a { color: blue; }
a { color: green; }

The old output makes blue win; keeping the final declaration after the hoisted rule makes green win. The added tests cover both this shorthand and the @at-root { ... } form.

@ai
ai merged commit c29d6fe into postcss:main Nov 7, 2026
3 checks passed
@ai

ai commented Nov 7, 2026

Copy link
Copy Markdown
Member

Thanks

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.

2 participants