Repository navigation
Open
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimeIssues related to the framework runtimecore: change detectionfreq2: medium
Milestone
Description
🐞 bug report
Affected Package
The issue is caused by package @angular/core (Ivy)Is this a regression?
Yes, works in non-Ivy.
Description
I suspect this happens as a result of having an Input property that is set directly (isExpanded="true") instead of using a binding ([isExpanded]="true"), and having the property setter call changeDetectorRef.detectChanges(). It should be noted that this works in non-ivy.
🔬 Minimal Reproduction
https://github.com/fr0/angular-test/tree/ivy
- Clone repo
git checkout ivynpm installnpm start- Open http://localhost:4200 in Chrome
- View browser console log
🔥 Exception or Error
core.js:5829 ERROR Error: ASSERTION ERROR: Should be run in update mode
at throwError (core.js:1164)
at assertEqual (core.js:1123)
at refreshView (core.js:12425)
at detectChangesInternal (core.js:13907)
at ViewRef.detectChanges (core.js:15373)
at ExpandableIfComponent.set isExpanded [as isExpanded] (expandable-if.component.ts:60)
at setInputsFromAttrs (core.js:13579)
at postProcessDirective (core.js:13335)
at instantiateAllDirectives (core.js:13234)
at createDirectivesInstances (core.js:12618)
🌍 Your Environment
Angular Version:
Angular CLI: 9.0.0-next.5
Node: 12.6.0
OS: darwin x64
Angular: 9.0.0-next.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.900.0-next.5
@angular-devkit/build-angular 0.900.0-next.5
@angular-devkit/build-optimizer 0.900.0-next.5
@angular-devkit/build-webpack 0.900.0-next.5
@angular-devkit/core 9.0.0-next.5
@angular-devkit/schematics 9.0.0-next.5
@angular/cli 9.0.0-next.5
@ngtools/webpack 9.0.0-next.5
@schematics/angular 9.0.0-next.5
@schematics/update 0.900.0-next.5
ng-packagr 5.5.1
rxjs 6.5.3
typescript 3.5.3
webpack 4.40.2
Reacted by Sebastian Podgajny, ZyoxNet, Johannes Millan, mishkolesnikov, Rohit Dandnayak, Luiz Avila, Craig Goldstone, Markus Chiarot, Trevor Daniels, Malik-AMotan and 9 more
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimeIssues related to the framework runtimecore: change detectionfreq2: medium
Activity
mhevery commentedon Oct 8, 2019
Please provide minimal reproduction with exact steps on how to reproduce it. We have limited time and can't go explore your application.
fr0 commentedon Oct 8, 2019
The error occurs for me under angular
9.0.0-next.5(which is what the linkedivybranch in the linked repo uses) when I runng serveand launchhttp://localhost:4200.So:
git checkout ivynpm installnpm startfr0 commentedon Oct 9, 2019
I verified that the problem still occurs with
9.0.0-next.8.kara commentedon Oct 15, 2019
@fr0 Thanks, I was able to reproduce. We'll add this to the list!
SebastianPodgajny commentedon Oct 24, 2019
@kara We are using angular without ngZone and this issue is happening all over our code base because we have a lot of manual change detection with




cdRef.detectChanges()Here is another example of this kind of error
pkozlowski-opensource commentedon Oct 29, 2019
@SebastianPodgajny the case you are mentioning seem to be different as compared to the originally reported here (different error message, different case).
Could you please open a new issue and provide a reduced reproduction scenario? Thnx!
18 remaining items
sviat9440 commentedon Oct 12, 2020
Temporary fix for me:
replace call
detectChanges()tomarkForCheck().qpi commentedon Dec 16, 2020
I have the same issue under Angular 10 when call detectChanges(). I tried to upgrade to 11 but still the same
id1945 commentedon Jan 11, 2021
I found that placing detectChanges() in the constructor caused an error. So I wrote it in the ngOnInt() function and it works properly with my project.
I hope to help someone here
jelbourn commentedon Jan 28, 2021
Copying notes on this from an internal tracker:
fix runtime assertion error
sciborrudnicki commentedon Feb 15, 2021
I use setTimeout(() => this.changeDetector.detectChanges(), 0);
aksheyjhalani27 commentedon Feb 16, 2021
Any updates so far on this.?
s3nt1n3lz21 commentedon Mar 17, 2021
This error appeared when I was calling detectChanges() in the constructor after subscribing to some data. I moved the subscription and detectChanges() to ngOnInit() instead and it disappeared.
blyndcide commentedon Jun 11, 2021
In Angular 12 this is happening even when not in a constructor. Simply calling .detectChanges() in an observable that, I don't know...initially runs too early and fast?, throws this error. Constructor has nothing in the body.
joepvl commentedon Jun 23, 2022
If you're running into this when writing tests and mocking a normally async call using
of(yourMockedResult), it could be because your component's code is subscribing to the observable in the constructor and callingchangeDetectorRef.detectChanges()in the callback. Because the call is async in your application, this does not pose an issue when running it, but mocking the observable usingof(...)is making it sync in this case, which is why Angular complains. A pragmatic solution: useof(yourMockedResult).pipe(delay(0))instead, which forces the observable to be async. That way, thechangeDetectorRef.detectChanges()call will be pushed further along in the event loop, giving Angular a chance to put everything in place. (That said, it's probably a good idea to move it tongOnInitif you can.)brianpooe commentedon Aug 23, 2023
Some of us cannot move the logic from the constructor to ngOnInit cause the application does not update as expected in that case using onPush strategy.
arturovt commentedon Sep 29, 2026
@JeanMeche this can be closed. Same class as #45577: a static attribute input is applied during creation, so calling detectChanges() from the setter re-enters change detection while the view is still in creation mode, which the assertion is reporting correctly rather than hiding.
Reported against 9.0.0-next.7 in 2019, milestone v9.x-candidates, no upvotes, no comments, and the framing is an Ivy-versus-ViewEngine regression, so the comparison cannot be run any more.
Running view work from an input setter is not supported: ngOnInit or afterNextRender is the place for it.