Skip to content

Commit 8cabb7a

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 7c1b4a4 commit 8cabb7a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/core/src/render3/after_render_hooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ export function afterNextRender(
345345
* A wrapper around a function to be used as an after render callback.
346346
*/
347347
class AfterRenderCallback {
348+
private zone = inject(NgZone);
348349
private errorHandler = inject(ErrorHandler, {optional: true});
349350

350351
constructor(
@@ -357,7 +358,7 @@ class AfterRenderCallback {
357358

358359
invoke() {
359360
try {
360-
this.callbackFn();
361+
this.zone.runOutsideAngular(this.callbackFn);
361362
} catch (err) {
362363
this.errorHandler?.handleError(err);
363364
}

0 commit comments

Comments
 (0)