-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Add option to afterRender* hooks to only run on global change detection #53232
Description
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
The afterRender and afterNextRender hooks currently trigger on any change detection. This could include a call to ChangeDetectorRef.detectChanges. There is no way to create a render hook that only runs when the global change detection is triggered (i.e. ApplicationRef.tick).
This is especially problematic for afterNextRender when the intent is almost always to run after the next global change detection or "after rendering this component". The problem is that there might be a ChangeDetectorRef.detectChanges call before the global ApplicationRef.tick might happen. This would mean that the component may not have been change detected/rendered when the hook runs.
Proposed solution
Add a property to the AfterRenderOptions to only run the hook after a global change detection (ApplicationRef.tick) rather than running it on any change detection (ChangeDetectorRef.detectChanges).
Alternatives considered
There's no alternative at the moment.