Skip to content

Change Detection Not Working with Routing in Zone-Less Application #39296

@markostanimirovic

Description

@markostanimirovic

🐞 bug report

zoneless-routing-bug

Affected Package

The issue is caused by package @angular/core

Is this a regression?

No

Description

Issue happens in zone-less environment when routing is used. If you remove <router-outlet></router-outlet> from app component template and put <app-counter></app-counter>, everything works fine.

Problem makes ɵmarkDirty(this) that is called immediately in ngOnInit method of counter component (see bellow Workaround 1). Then, when you click on increment or decrement button, rootContext.flags is equal to 1 (DetectChanges) instead of 0 (Empty), and because of that, tick is never scheduled:

schedule-tick

🔬 Minimal Reproduction

  1. Clone https://github.com/markostanimirovic/zoneless-routing-bug repo
  2. Run npm install
  3. Run npm start
  4. Click on increment/decrement buttons, observe that count value is not changed
  5. Navigate to Counter 2, observe that count paragraph disappeared
  6. Navigate back to Counter, observe that count paragraph disappeared too

Workaround 1

  1. Open counter.component.ts file
  2. Comment out lines 24-29
  3. Uncomment lines 32-38

Workaround 2

  1. Open app.component.ts file
  2. Swap ɵmarkDirty(this) with ɵdetectChanges(this) on line 21

🌍 Your Environment

Angular Version: 10.1.6

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimearea: zonesIssues related to zone.jscore: change detectionstate: confirmedstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions