Skip to content

Commit 760e284

Browse files
atscottAndrewKushnir
authored andcommitted
Revert "fix(core): render hooks should not specifically run outside the Angular zone (#55399)" (#55624)
This reverts commit 7e89753. Running render hooks inside the zone is specifically problematic for `afterRender` hooks. If the callback has async task, it would cause an infinite change detection. In addition, updating state in render hooks is generally discourages and certainly should update state in a way that notifies Angular of the change (either via signal or with `markForCheck`) rather than relying on ZoneJS to pick it up (which would only work if the change is done inside an async task). PR Close #55624
1 parent 3818436 commit 760e284

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/core/src/render3/after_render_hooks.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export function afterNextRender(
331331
* A wrapper around a function to be used as an after render callback.
332332
*/
333333
class AfterRenderCallback {
334+
private zone = inject(NgZone);
334335
private errorHandler = inject(ErrorHandler, {optional: true});
335336

336337
constructor(readonly phase: AfterRenderPhase, private callbackFn: VoidFunction) {
@@ -340,7 +341,7 @@ class AfterRenderCallback {
340341

341342
invoke() {
342343
try {
343-
this.callbackFn();
344+
this.zone.runOutsideAngular(this.callbackFn);
344345
} catch (err) {
345346
this.errorHandler?.handleError(err);
346347
}

0 commit comments

Comments
 (0)