GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(compiler): do not add the content attribute to nested `&` selectors by LordKay-sudo · Pull Request #72234 · angular/angular

Conversation

@LordKay-sudo

@LordKay-sudo LordKay-sudo commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #71050.

Since nested rules are scoped (#69885), :host { &.md { } } compiles to [_nghost-c1] { &.md[_ngcontent-c1] { } }. The host element doesn't carry its own content attribute, so the rule never matches.

In a nested rule & is the parent selector, and the parent is already scoped. So a compound selector with & outside of parentheses (&.md, &:hover, &[disabled], &::before, �utton&) is now left alone. That also covers :where(&.md) and :is(&.md, .child), whose arguments are scoped one by one. Descendants such as & .child and .child still get the content attribute, :not(&) is still scoped, and a top-level & is unchanged.

This doesn't try to work out whether the parent rule is :host, so :host(...), deeper nesting and parents like :is(:host > .x) all behave the same way. The one visible change outside :host is that .parent { &.modifier { } } now gives &.modifier instead of &.modifier[contenta]. It matches the same elements because & is already .parent[contenta], and I updated the two existing expectations for it.

I ran //packages/compiler/test:test and it passes. Without the change in shadow_css.ts, the new :host specs and the two updated ones fail.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@LordKay-sudo
fix(compiler): do not add the content attribute to nested & selectors
bfd9b83
Since nested rules are scoped, a compound selector containing `&`, such as
`&.md` inside `:host`, got the content attribute. There `&` is the host
element, which only has the host attribute, so the rule stopped matching.

In a nested rule `&` stands for the parent selector, which is already
scoped, so a compound that contains `&` outside of parentheses is now left
as it is. Its descendants (`& .child`) are still scoped. Rules at the top
level are not affected.

Fixes angular#71050
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Nov 27, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 27, 2026
@pullapprove
pullapprove Bot requested a review from atscott November 27, 2026 05:17
@atscott
atscott requested review from mattrbeck and removed request for atscott November 27, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mattrbeck mattrbeck Awaiting requested review from mattrbeck

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Milestone

Backlog

Development

Successfully merging this pull request may close these issues.

Nested & selectors inside :host get _ngcontent attribute and no longer match (regression in 22.2.0)

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@LordKay-sudo
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.