Is this a regression?
The previous version in which this bug was not present was
No response
Description
Root cause
HighContrastModeDetector is declared without providedIn: 'root':
The first inject(HighContrastModeDetector) call from A11yModule.constructor() therefore creates the instance in the route-scoped injector that A11yModule is imported into (via a Material component). withAutoCleanupInjectors() tears down that injector on navigation. Next navigation triggers a fresh A11yModule constructor whose inject-chain references the destroyed injector → NG0205.
Fix suggestion: Add providedIn: 'root' to the @Injectable of HighContrastModeDetector (and audit the other a11y services for the same shape).
Workaround
Add HighContrastModeDetector to root providers manually:
providers: [..., HighContrastModeDetector]
### Reproduction
- Angular 22.2.0, @angular/cdk 22.2.1
- `provideRouter(..., withAutoCleanupInjectors())`
- Lazy-loaded route uses any Angular Material component (MatInput, MatButton, MatDialog, ...)
- Navigate: /route-a → /route-b → /route-a (triggers A11yModule twice)
### Expected Behavior
Navigation succeeds.
### Actual Behavior
Second visit to a route that imports A11yModule throws:
`ERROR Error: NG0205` (InjectorAlreadyDestroyed)
Stack bottoms out at `HighContrastModeDetector` factory being called in an already-destroyed route injector.
### Environment
- Angular: 22.2.0 (@angular/core, @angular/common, @angular/router, @angular/platform-browser, @angular/compiler-cli)
- @angular/cdk: 22.2.0 (also reproduced on 22.2.1 and 22.3.0-next.0 — unchanged a11y code)
- @angular/material: 22.2.0
- @angular/cli / @angular/build: 22.2.0
- Node: v24.15.0
- npm: 11.12.1
- TypeScript target: ES2022, moduleResolution: bundler, strict: true, strictTemplates: true
- Rendering: ZoneJS active (zoneless-compatible code via Signals)
- Browser (via Playwright): Chromium 153 (headless + headed)
- OS: Windows 11 Pro 10.0.26200 (CI reproduces more frequently on Linux containers)
- Router config:
provideRouter(
routes,
withComponentInputBinding(),
withRouterConfig({ paramsInheritanceStrategy: "always" }),
withPreloading(PreloadAllModules),
withAutoCleanupInjectors(),
)
Is this a regression?
The previous version in which this bug was not present was
No response
Description
Root cause
HighContrastModeDetectoris declared withoutprovidedIn: 'root':The first
inject(HighContrastModeDetector)call fromA11yModule.constructor()therefore creates the instance in the route-scoped injector that A11yModule is imported into (via a Material component).withAutoCleanupInjectors()tears down that injector on navigation. Next navigation triggers a fresh A11yModule constructor whose inject-chain references the destroyed injector → NG0205.Fix suggestion: Add
providedIn: 'root'to the@Injectableof HighContrastModeDetector (and audit the other a11y services for the same shape).Workaround
Add
HighContrastModeDetectorto root providers manually: