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 — Nested `&` selectors inside `:host` get `_ngcontent` attribute and no longer match (regression in 22.2.0) · Issue #71050 · angular/angular

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

New issue
Copy link
New issue
Copy link
Open
#72234
Open
Nested & selectors inside :host get _ngcontent attribute and no longer match (regression in 22.2.0)#71050
#72234
Copy link
Labels
area: compilerIssues related to `ngc`, Angular's template compilercore: CSS encapsulation
Milestone
needsTriage

Description

@anhallbe
anhallbe
opened on Sep 29, 2026
Issue body actions

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

Since d0d7f57 (#69885, "fix(compiler): scope nested CSS rules"), selectors nested with & inside a :host rule are scoped with the content attribute. & there refers to the host element, which only has the _nghost-* attribute, so the rule never matches.

@Component({
  selector: 'app-avatar',
  host: { class: 'md' },
  template: '',
  styles: `
    :host {
      display: block;
      &.md { width: 70px; }
    }
  `,
})
export class Avatar {}

Output of the emulated encapsulation:

Version Output
22.1.8 [_nghost-c1] { display: block; &.md { width: 70px; } }
22.2.0 [_nghost-c1] { display: block; &.md[_ngcontent-c1] { width: 70px; } }

In 22.2.0 the rule resolves to [_nghost-c1].md[_ngcontent-c1]. The host element carries _nghost-c1 and its parent's _ngcontent-*, so &.md no longer applies.

Minimal repro with the compiler directly:

import { encapsulateStyle } from '@angular/compiler';
encapsulateStyle(':host { &.md { width: 70px } }', 'c1');
// 22.1.8: [_nghost-c1] { &.md { width: 70px } }
// 22.2.0: [_nghost-c1] { &.md[_ngcontent-c1] { width: 70px } }

Expected: a compound selector that starts with & directly under :host (e.g. &.md, &:hover, &[attr]) is left unscoped, or scoped with the host attribute. Descendant selectors (& .child, .child) should still get the content attribute.

packages/compiler/test/shadow_css/nesting_spec.ts covers :host(.foo) { .child {} } and .parent { &.modifier {} }, but not :host { &.modifier {} }.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/bhxywn3c?file=src%2Fmain.ts

Please provide the exception or error you saw

None. The styles silently stop applying.

Please provide the environment you discovered this bug in (run ng version)

Angular CLI       : 22.2.0
Angular           : 22.2.0
Node.js           : 24.16.0
Package Manager   : npm 11.13.0
Operating System  : darwin arm64

┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                           │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular/animations               │ 22.2.0            │ ~22.2.0           │
│ @angular/build                    │ 22.2.0            │ ~22.2.0           │
│ @angular/cdk                      │ 22.2.0            │ ~22.2.0           │
│ @angular/cli                      │ 22.2.0            │ ~22.2.0           │
│ @angular/common                   │ 22.2.0            │ ~22.2.0           │
│ @angular/compiler                 │ 22.2.0            │ ~22.2.0           │
│ @angular/compiler-cli             │ 22.2.0            │ ~22.2.0           │
│ @angular/core                     │ 22.2.0            │ ~22.2.0           │
│ @angular/forms                    │ 22.2.0            │ ~22.2.0           │
│ @angular/platform-browser         │ 22.2.0            │ ~22.2.0           │
│ @angular/platform-browser-dynamic │ 22.2.0            │ ~22.2.0           │
│ @angular/router                   │ 22.2.0            │ ~22.2.0           │
│ ng-packagr                        │ 22.2.2            │ ^22.2.2           │
│ rxjs                              │ 7.8.2             │ ^7.8.2            │
│ typescript                        │ 6.0.3             │ ~6.0.3            │
│ vitest                            │ 5.0.2             │ ^5.0.2            │
│ zone.js                           │ 0.16.3            │ ~0.16.0           │
└───────────────────────────────────┴───────────────────┴───────────────────┘

Anything else?

We JIT-compile third-party components at runtime, so their authors hit this without being able to change the build.

The repro uses aot: false. In our AOT CLI build, the CSS pipeline flattened :host { &.on {} } to :host.on {} before ShadowCss ran, which hides the bug. It shows up whenever unflattened nested CSS reaches the compiler, e.g. JIT.

Activity

  1. angular-robot
    added
    area: compilerIssues related to `ngc`, Angular's template compiler
    gemini-triaged
    on Sep 29, 2026
  2. ngbot
    added this to the needsTriage milestone on Sep 29, 2026
  3. JeanMeche
    added
    core: CSS encapsulation
    and removed
    gemini-triaged
    on Sep 29, 2026
  4. rene-schakmann
    added 2 commits that reference this issue on Oct 3, 2026

    fix(compiler): do not scope nested compound selectors starting with `&`

    This issue will close once commit d6a053c is merged into the 'main' branch.
    d6a053c

    fix(compiler): do not scope nested compound selectors starting with `&`

    This issue will close once commit d941ebf is merged into the 'main' branch.
    d941ebf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compilerIssues related to `ngc`, Angular's template compilercore: CSS encapsulation

    Type

    No type

    Projects

    No projects

      Milestone

      • needsTriageNo due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.