New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Ivy] ASSERTION ERROR: Should be run in update mode #32756
Comments
Please provide minimal reproduction with exact steps on how to reproduce it. We have limited time and can't go explore your application. |
The error occurs for me under angular So:
|
I verified that the problem still occurs with |
@fr0 Thanks, I was able to reproduce. We'll add this to the list! |
@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
|
@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! |
A typical scenario, where this error occurs is something along those lines: @Input()
public set readonly(value: boolean) {
// somewhere in other function:
this.changeDetectorRef.detectChanges();
} Basically we are invoking an input setter in the creation mode (this might happen if an input is set from a static attribute). 2 possible solutions here:
|
Any update on this? |
PR is still open |
Yeah, but there was no activity on that PR for 6 months now. Last comment from @pkozlowski-opensource is only about a month old. Anyway the problem, in my case anyway, seems to have disappeared when I removed OnPush from components that relied on markDirty to trigger CD. |
Is there a solution planned for this issue? It prevents me from moving to angular 9. |
Same issue here. Some background: I'm building an Electron Application using Angular 9.0.6 + Electron 8 + @angular-guru/electron-builder (as builder) Using the code below triggers the error: import { execSync } from 'child_process';
import { ChangeDetectorRef, Component } from '@angular/core';
// ... code to construct component
constructor(private changeDetectorRef: ChangeDetectorRef) {
const data = execSync(`some command line executable`);
this._init(JSON.parse(data.toString('utf8')));
}
private _init(data) {
// some processing with data
this.changeDetectorRef.detectChanges(); // this line throws the error
} Removing that line, or changing to as below, solved my problem: import { exec } from 'child_process';
import { ChangeDetectorRef, Component } from '@angular/core';
// ... code to construct component
constructor(private changeDetectorRef: ChangeDetectorRef) {
exec(`some command line executable`, (data) => {
this._init(JSON.parse(data));
});
}
private _init(data: Button[]) {
// some processing
this.changeDetectorRef.detectChanges();
} Hope this could be helpful for someone.
|
same problem. |
Same... :( |
This breaks a big chunk of our application, any updates on this issue? |
same here :c |
oh, the same issue (angular 9.1.7 with { ngZone: 'noop' }) resolved it by moving logic out of constructor to ngOnInit |
Does anybody know when this will be fixed? |
Any Update on Above Issue? |
Hello, any update? This could be a blocker for projects trying to upgrade to Angular 9. |
@BzenkoSergey It worked! You are a champ! Looked through my company's project for ALL logic defined in components constructors, and moved anything I found to ngOnInit, and bam, no error. |
I believe this is bad practice to have some logic within constructor in any case. |
For anyone coming here that has a similar issue, what I had previously in my project was a setter on a |
Temporary fix for me: |
I have the same issue under Angular 10 when call detectChanges(). I tried to upgrade to 11 but still the same |
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. |
Copying notes on this from an internal tracker:
|
I use setTimeout(() => this.changeDetector.detectChanges(), 0); |
Any updates so far on this.? |
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. |
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. |
If you're running into this when writing tests and mocking a normally async call using |
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. |
馃悶 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 callchangeDetectorRef.detectChanges()
. It should be noted that this works in non-ivy.馃敩 Minimal Reproduction
https://github.com/fr0/angular-test/tree/ivy
git checkout ivy
npm install
npm start
馃敟 Exception or Error
馃實 Your Environment
Angular Version:
The text was updated successfully, but these errors were encountered: