fix(core): Prevent markForCheck
during change detection from causin…
#54900
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…g infinite loops
This change updates the approach to the loop in
ApplicationRef.tick
for allowing state updates inafterRender
hooks. It is valid to update state in render hooks and we need to ensure we refresh views that may be marked for check in these hooks (this can happen simply as a result of focusing an element). This change ensures that the behavior ofmarkForCheck
with respect to this loop does not change while we are actively running change detection on a view tree.This approach also has the benefit of preventing a regression for #18917, where updating state in animation listeners can cause
ExpressionChanged...Error
This should be allowed - there is nothing wrong with respect to unidirectional data flow in this case.There may be other cases in the future where it is valid to update state. Rather than wrapping the render hooks and the animation flushing in something which flips a global state flag, the idea here is that
markForCheck
is safe and valid in all cases whenever change detection is not actively running.