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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected supression (or undetected) ExpressionChangedAfterItHasBeenCheckedError #44277
Comments
This is an interesting case. The angular/packages/core/src/change_detection/change_detection_util.ts Lines 11 to 25 in 8878183
I presume that this is done in the assumption that using any of its primitive properties in some (child) template would then report an |
Oh. I was under the impression that ngFor uses |
It does, but that's unrelated to After the primary change detection run has finished will Angular run its |
So what are the further steps from here? Not that I'm impatient, just curious, when the eventual triage might happen? |
Fwiw, the new |
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
During the development, I've bumped into some change detection case that is somewhat non-trivial and I felt like maybe Angular doesn't do enough to properly flag it. I'm not sure if this a bug or not (perhaps not), maybe it should be just an improvement. That said, I'd still like to understand what's going on, because I've wasted a lot of time looking in a completely wrong place.
In the example provided in the link, when you click the button, a new component appears. The (fabricated for this example) purpose was for it to update the two props above (by pushing a new value into an observable that resides within a shared service between child and parent and parent subscribes to it) - but it doesn't happen. When you click it again, you finally see it (next change detection triggered, obviously).
After a long and arduous process, now I do know what's wrong here and how to fix it with regards to change detection cycle, child updating parent's DOM in the same change detection macrotask, etc. What I'm not sure about is: why the error isn't thrown, when it's clearly a case of a new value being pushed in the same tick after the parent DOM update (which is clearly demonstrated by the values not updating the first time)?
You can easily influence this by pushing two objects in HelloComponent or by pushing just an empty array into observable in parent, instead of initial object. Then, you would (correctly) see the standard ExpressionChangedAfterItHasBeenCheckedError error, as expected.
It's still an overwrite with a new reference to a new array, so how the comparison works here behind the scenes? Why the expression (*ngFor in this case, in parent) is apparently evaluated to "the same value" and thus not throwing an error, even if it obviously contains a new array with another object filled with props with another values? Is it because *ngFor interpolates to a string at this stage (or uses some other simplification, like only checking array length, comparing by shallow value etc.)?
Seems like the error should be thrown here. It might be "working as intended", but that "intended" is confusing without a warning.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/angular-jkshfv?file=src%2Fapp%2Fhello.component.ts
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
I do realize that this borderlines on a support request, but, again, the intention here is to improve the framework to throw some kind of warning for these cases, as opposed to doing nothing, as it is right now.
The text was updated successfully, but these errors were encountered: