Skip to content

afterRender hook called multiple times when there are multiple root views in the application #52429

@atscott

Description

@atscott

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

The afterRender hooks are called after each root view refreshes. This happens because ApplicationRef.tick calls detectChanges on each root view

for (let view of this._views) {
view.detectChanges();
}

and the hooks are called after running change detection on any view
} finally {
if (!checkNoChangesMode) {
rendererFactory.end?.();
// One final flush of the effects queue to catch any effects created in `ngAfterViewInit` or
// other post-order hooks.
environment.inlineEffectRunner?.flush();
// Invoke all callbacks registered via `after*Render`, if needed.
afterRenderEventManager?.end();
}

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-cnr3id

Please provide the exception or error you saw

`afterRender` is called after each root view is refreshed. `ApplicationRef.tick` should only run the render hooks one time, after all root views are refreshed.

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions