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): run afterRender callbacks outside of the Angular zone #51385

Closed
wants to merge 1 commit into from

Conversation

devknoll
Copy link
Contributor

@devknoll devknoll commented Aug 16, 2023

afterRender should run outside of the Angular zone so that it does not trigger further CD cycles

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Callbacks are executed in the Angular zone, causing patched APIs like setTimeout to trigger subsequent change detection cycles, and further afterRender callbacks.

Issue Number: #51343

What is the new behavior?

Callbacks are always executed outside of the Angular zone, preventing accidental infinite render loops.

Does this PR introduce a breaking change?

  • Yes
  • No

afterRender is in developer preview, and so this is not considered a breaking change.

Other information

Closes #51343

@pullapprove pullapprove bot requested a review from atscott August 16, 2023 15:58
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Aug 16, 2023
@pkozlowski-opensource pkozlowski-opensource added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime labels Aug 16, 2023
@ngbot ngbot bot modified the milestone: Backlog Aug 16, 2023
@atscott atscott added action: discuss and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 16, 2023
@devknoll devknoll force-pushed the x-after-render-outside-zone branch 2 times, most recently from d5c9d9f to b5ba43d Compare August 16, 2023 17:10
@devknoll
Copy link
Contributor Author

cc @kara

@alxhub alxhub added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release and removed action: discuss labels Aug 28, 2023
@ngbot
Copy link

ngbot bot commented Aug 28, 2023

I see that you just added the action: merge label, but the following checks are still failing:
    failure conflicts with base branch "main"
    pending 2 pending code reviews

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@alxhub alxhub added target: patch This PR is targeted for the next patch release and removed target: minor This PR is targeted for the next minor release labels Aug 28, 2023
@alxhub
Copy link
Member

alxhub commented Aug 28, 2023

@devknoll can you change the commit to fix, not feat? Our merge tooling will reject merging a feat commit to the 16.2.x branch.

@alxhub alxhub added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Aug 28, 2023
@devknoll devknoll changed the title feat(core): Run afterRender callbacks outside of the Angular zone fix(core): run afterRender callbacks outside of the Angular zone Aug 28, 2023
@angular-robot angular-robot bot removed the detected: feature PR contains a feature commit label Aug 28, 2023
afterRender should run outside of the Angular zone so that it does not trigger further CD cycles
@kara kara added action: presubmit The PR is in need of a google3 presubmit merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Aug 28, 2023
@kara kara added the action: merge The PR is ready for merge by the caretaker label Aug 28, 2023
@jessicajaniuk
Copy link
Contributor

@devknoll I see this has action: presubmit, but this is showing as passing. Is another presubmit needed? Or a TGP?

@kara
Copy link
Contributor

kara commented Aug 28, 2023

@jessicajaniuk oh, my mistake. I added the label bc I didn't see it already ran. Will remove.

@kara kara removed the action: presubmit The PR is in need of a google3 presubmit label Aug 28, 2023
@jessicajaniuk
Copy link
Contributor

@devknoll I'm going to update this to target: minor, but we'll need a patch PR to get it into 16.2.x. Please create that at your leisure.

@jessicajaniuk jessicajaniuk added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Aug 28, 2023
@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit 3a19d6b.

thomasturrell pushed a commit to thomasturrell/angular that referenced this pull request Aug 29, 2023
…ular#51385)

afterRender should run outside of the Angular zone so that it does not trigger further CD cycles

PR Close angular#51385
@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 Sep 28, 2023
@devknoll devknoll deleted the x-after-render-outside-zone branch September 28, 2023 00:10
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…ular#51385)

afterRender should run outside of the Angular zone so that it does not trigger further CD cycles

PR Close angular#51385
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 target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: throw an error in case of afterRender misuse.
6 participants