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

After render app ref tick #52455

Closed
wants to merge 2 commits into from
Closed

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Oct 30, 2023

he afterRender hooks currently run after ApplicationRef.tick but
also run after any call to ChangeDetectorRef.detectChanges. This is
problematic because code which uses afterRender cannot expect the
component it's registered from to be rendered when the callback
executes. If there is a call to ChangeDetectorRef.detectChanges before
the global change detection, that will cause the hooks to run earlier
than expected.

This behavior is somewhat of a blocker for the zoneless project. There
is plenty of application code that do things like setTimeout(() => doSomethingThatExpectsComponentToBeRendered()), NgZone.onStable(() => ...) or ApplicationRef.onStable.... ApplicationRef.onStable
should likely work similarly, but all of these are really wanting an API
that is afterRender with the requirement that the hook runs after the
global render, not an individual CDRef instance.

This change updates the afterRender hooks to only run when
ApplicationRef.tick happens.

fixes #52429
fixes #53232

@atscott atscott added target: rc This PR is targeted for the next release-candidate area: core Issues related to the framework runtime labels Oct 30, 2023
@ngbot ngbot bot added this to the Backlog milestone Oct 30, 2023
@atscott atscott marked this pull request as draft October 30, 2023 21:59
@atscott atscott modified the milestones: Backlog, v17-final Oct 30, 2023
@atscott atscott force-pushed the afterRenderAppRefTick branch 4 times, most recently from cd2e2ab to de2b943 Compare November 8, 2023 17:56
@atscott atscott added target: patch This PR is targeted for the next patch release and removed target: rc This PR is targeted for the next release-candidate labels Nov 8, 2023
@atscott atscott requested a review from alxhub November 8, 2023 17:58
@atscott atscott marked this pull request as ready for review November 8, 2023 17:58
@alxhub alxhub removed this from the v17-final milestone Nov 9, 2023
@ngbot ngbot bot added this to the Backlog milestone Nov 9, 2023
@atscott atscott force-pushed the afterRenderAppRefTick branch 5 times, most recently from d8d8e31 to c344e24 Compare November 16, 2023 18:49
@atscott atscott force-pushed the afterRenderAppRefTick branch 7 times, most recently from 97dd35f to bc3118b Compare December 14, 2023 17:21
@atscott atscott added the action: merge The PR is ready for merge by the caretaker label Jan 4, 2024
@ngbot
Copy link

ngbot bot commented Jan 4, 2024

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "google-internal-tests" is failing
    pending status "pullapprove" is pending
    pending 3 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.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@@ -59,7 +59,7 @@ export const enum RuntimeErrorCode {
// (undocumented)
IMPORT_PROVIDERS_FROM_STANDALONE = 800,
// (undocumented)
INFINITE_CHANGE_DETECTION = 103,
INFINITE_CHANGE_DETECTION = 102,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this change, or should error codes be permanent? (even if they're not documented?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to revert this. I think I had the same question in the past and I was informed that we do not commit to keeping the error codes stable. @AndrewKushnir @alxhub

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to revert this error code change because I also agree with there being value in keeping them stable. Even if we decide in the meeting that it's not something we will do, there's really no reason to change it in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to keep error codes stable (this is the main point of having golden files for them). I was under impression that those code represent similar conditions under which the error occurs, thus the change was ok. If it's not the case, let's keep the code stable.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for now on the error code, but I added an item to the team meeting agenda to discuss at some point (I feel like there's some value in keeping them stable)

Reviewed-for: public-api

@atscott
Copy link
Contributor Author

atscott commented Jan 8, 2024

This PR was merged into the repository by commit dfcf0d5.

@atscott atscott closed this in dfcf0d5 Jan 8, 2024
atscott added a commit that referenced this pull request Jan 8, 2024
…52455)

The `afterRender` hooks currently run after `ApplicationRef.tick` but
also run after any call to `ChangeDetectorRef.detectChanges`. This is
problematic because code which uses `afterRender` cannot expect the
component it's registered from to be rendered when the callback
executes. If there is a call to `ChangeDetectorRef.detectChanges` before
the global change detection, that will cause the hooks to run earlier
than expected.

This behavior is somewhat of a blocker for the zoneless project. There
is plenty of application code that do things like `setTimeout(() =>
doSomethingThatExpectsComponentToBeRendered())`, `NgZone.onStable(() =>
...)` or `ApplicationRef.onStable...`. `ApplicationRef.onStable` is a
should likely work similarly, but all of these are really wanting an API
that is `afterRender` with the requirement that the hook runs after the
global render, not an individual CDRef instance.

This change updates the `afterRender` hooks to only run when
`ApplicationRef.tick` happens.

fixes #52429
fixes #53232

PR Close #52455
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…ngular#52455)

The `afterRender` hooks currently run after `ApplicationRef.tick` but
also run after any call to `ChangeDetectorRef.detectChanges`. This is
problematic because code which uses `afterRender` cannot expect the
component it's registered from to be rendered when the callback
executes. If there is a call to `ChangeDetectorRef.detectChanges` before
the global change detection, that will cause the hooks to run earlier
than expected.

This behavior is somewhat of a blocker for the zoneless project. There
is plenty of application code that do things like `setTimeout(() =>
doSomethingThatExpectsComponentToBeRendered())`, `NgZone.onStable(() =>
...)` or `ApplicationRef.onStable...`. `ApplicationRef.onStable` is a
should likely work similarly, but all of these are really wanting an API
that is `afterRender` with the requirement that the hook runs after the
global render, not an individual CDRef instance.

This change updates the `afterRender` hooks to only run when
`ApplicationRef.tick` happens.

fixes angular#52429
fixes angular#53232

PR Close angular#52455
rlmestre pushed a commit to rlmestre/angular that referenced this pull request Jan 26, 2024
…ngular#52455)

The `afterRender` hooks currently run after `ApplicationRef.tick` but
also run after any call to `ChangeDetectorRef.detectChanges`. This is
problematic because code which uses `afterRender` cannot expect the
component it's registered from to be rendered when the callback
executes. If there is a call to `ChangeDetectorRef.detectChanges` before
the global change detection, that will cause the hooks to run earlier
than expected.

This behavior is somewhat of a blocker for the zoneless project. There
is plenty of application code that do things like `setTimeout(() =>
doSomethingThatExpectsComponentToBeRendered())`, `NgZone.onStable(() =>
...)` or `ApplicationRef.onStable...`. `ApplicationRef.onStable` is a
should likely work similarly, but all of these are really wanting an API
that is `afterRender` with the requirement that the hook runs after the
global render, not an individual CDRef instance.

This change updates the `afterRender` hooks to only run when
`ApplicationRef.tick` happens.

fixes angular#52429
fixes angular#53232

PR Close angular#52455
danieljancar pushed a commit to danieljancar/angular that referenced this pull request Jan 26, 2024
…ngular#52455)

The `afterRender` hooks currently run after `ApplicationRef.tick` but
also run after any call to `ChangeDetectorRef.detectChanges`. This is
problematic because code which uses `afterRender` cannot expect the
component it's registered from to be rendered when the callback
executes. If there is a call to `ChangeDetectorRef.detectChanges` before
the global change detection, that will cause the hooks to run earlier
than expected.

This behavior is somewhat of a blocker for the zoneless project. There
is plenty of application code that do things like `setTimeout(() =>
doSomethingThatExpectsComponentToBeRendered())`, `NgZone.onStable(() =>
...)` or `ApplicationRef.onStable...`. `ApplicationRef.onStable` is a
should likely work similarly, but all of these are really wanting an API
that is `afterRender` with the requirement that the hook runs after the
global render, not an individual CDRef instance.

This change updates the `afterRender` hooks to only run when
`ApplicationRef.tick` happens.

fixes angular#52429
fixes angular#53232

PR Close angular#52455
amilamen pushed a commit to amilamen/angular that referenced this pull request Jan 26, 2024
…ngular#52455)

The `afterRender` hooks currently run after `ApplicationRef.tick` but
also run after any call to `ChangeDetectorRef.detectChanges`. This is
problematic because code which uses `afterRender` cannot expect the
component it's registered from to be rendered when the callback
executes. If there is a call to `ChangeDetectorRef.detectChanges` before
the global change detection, that will cause the hooks to run earlier
than expected.

This behavior is somewhat of a blocker for the zoneless project. There
is plenty of application code that do things like `setTimeout(() =>
doSomethingThatExpectsComponentToBeRendered())`, `NgZone.onStable(() =>
...)` or `ApplicationRef.onStable...`. `ApplicationRef.onStable` is a
should likely work similarly, but all of these are really wanting an API
that is `afterRender` with the requirement that the hook runs after the
global render, not an individual CDRef instance.

This change updates the `afterRender` hooks to only run when
`ApplicationRef.tick` happens.

fixes angular#52429
fixes angular#53232

PR Close angular#52455
@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 Feb 8, 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 target: patch This PR is targeted for the next patch release
Projects
None yet
5 participants