Skip to content

Add option to afterRender* hooks to only run on global change detection #53232

@atscott

Description

@atscott

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimefeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions