Skip to content
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

fix(core): Prevent markForCheck during change detection from causin… #54900

Closed
wants to merge 1 commit into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Mar 15, 2024

…g infinite loops

This change updates the approach to the loop in ApplicationRef.tick for allowing state updates in afterRender 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 of markForCheck 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.

@atscott atscott force-pushed the refreshloop branch 5 times, most recently from 004f259 to de04163 Compare March 15, 2024 22:53
@atscott atscott marked this pull request as ready for review March 18, 2024 15:47
@atscott
Copy link
Contributor Author

atscott commented Mar 18, 2024

TGP=https://fusion2.corp.google.com/presubmit/616238528/OCL:616238528:BASE:616332980:1710565092125:330cb602;groups=PossiblyNewlyFailing/targets

2 test-only failures. One pre-existing failure (with the fix already submitted).

@atscott atscott added area: core Issues related to the framework runtime target: major This PR is targeted for the next major release labels Mar 18, 2024
@ngbot ngbot bot added this to the Backlog milestone Mar 18, 2024
…g infinite loops

This change updates the approach to the loop in `ApplicationRef.tick`
for allowing state updates in `afterRender` 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 of `markForCheck`
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 angular#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.
@atscott atscott added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Mar 18, 2024
@atscott
Copy link
Contributor Author

atscott commented Mar 18, 2024

caretaker note: green TGP (other than mentioned failures that have been/are being fixed)

@alxhub
Copy link
Member

alxhub commented Mar 18, 2024

This PR was merged into the repository by commit 314112d.

@alxhub alxhub closed this in 314112d Mar 18, 2024
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
…g infinite loops (angular#54900)

This change updates the approach to the loop in `ApplicationRef.tick`
for allowing state updates in `afterRender` 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 of `markForCheck`
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 angular#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.

PR Close angular#54900
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants