-
Notifications
You must be signed in to change notification settings - Fork 27.1k
afterRender hook called multiple times when there are multiple root views in the application #52429
Copy link
Copy link
Closed
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecore: lifecycle hooks
Milestone
Description
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
angular/packages/core/src/application_ref.ts
Lines 1057 to 1059 in bdd61c7
| for (let view of this._views) { | |
| view.detectChanges(); | |
| } |
and the hooks are called after running change detection on any view
angular/packages/core/src/render3/instructions/change_detection.ts
Lines 70 to 80 in bdd61c7
| } 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecore: lifecycle hooks