Skip to content

Commit a177abe

Browse files
atscottAndrewKushnir
authored andcommitted
fix(core): render hooks should not specifically run outside the Angular zone (#55399)
The timing of render hook execution is almost entirely identical to `ngZone.onMicrotaskEmpty`. Developers working towards zoneless compatibility will need to migrate `onMicrotaskEmpty` calls to use `afterNextRender`/`afterRender` instead. This, however, would lead to confusing issues if there are promises in the callbacks because `onMicrotaskEmpty` emits inside the Angular zone while render hooks execute outside today. This is problematic because it's not documented and does not produce any notification or error message when async work is done inside the hooks that requires change detection. Instead, change detection simply does not run, and this behavior has proven to be surprising to developers who are used to ZoneJS change detection behavior. fixes #55299 PR Close #55399
1 parent a5c57c7 commit a177abe

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

packages/core/src/render3/after_render_hooks.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ 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);
335334
private errorHandler = inject(ErrorHandler, {optional: true});
336335

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

342341
invoke() {
343342
try {
344-
this.zone.runOutsideAngular(this.callbackFn);
343+
this.callbackFn();
345344
} catch (err) {
346345
this.errorHandler?.handleError(err);
347346
}

0 commit comments

Comments
 (0)