angular/packages/core/src/defer
Andrew Scott dfcf0d5882 fix(core): afterRender hooks now only run on ApplicationRef.tick (#52455)
The `afterRender` hooks currently run after `ApplicationRef.tick` but
also run after any call to `ChangeDetectorRef.detectChanges`. This is
problematic because code which uses `afterRender` cannot expect the
component it's registered from to be rendered when the callback
executes. If there is a call to `ChangeDetectorRef.detectChanges` before
the global change detection, that will cause the hooks to run earlier
than expected.

This behavior is somewhat of a blocker for the zoneless project. There
is plenty of application code that do things like `setTimeout(() =>
doSomethingThatExpectsComponentToBeRendered())`, `NgZone.onStable(() =>
...)` or `ApplicationRef.onStable...`. `ApplicationRef.onStable` is a
should likely work similarly, but all of these are really wanting an API
that is `afterRender` with the requirement that the hook runs after the
global render, not an individual CDRef instance.

This change updates the `afterRender` hooks to only run when
`ApplicationRef.tick` happens.

fixes #52429
fixes #53232

PR Close #52455
2024-01-08 11:30:27 -08:00
..
cleanup.ts refactor(core): defer triggers cleanup (#52291) 2023-10-23 12:00:18 -07:00
discovery.ts refactor(core): better organization of @defer runtime code (#52152) 2023-10-12 12:43:54 +02:00
dom_triggers.ts fix(core): afterRender hooks now only run on ApplicationRef.tick (#52455) 2024-01-08 11:30:27 -08:00
idle_scheduler.ts refactor(core): defer triggers cleanup (#52291) 2023-10-23 12:00:18 -07:00
instructions.ts fix(core): cleanup loading promise when no dependencies are defined (#53031) 2023-11-20 08:54:41 -08:00
interfaces.ts refactor(core): defer triggers cleanup (#52291) 2023-10-23 12:00:18 -07:00
timer_scheduler.ts refactor(core): defer triggers cleanup (#52291) 2023-10-23 12:00:18 -07:00
utils.ts fix(core): handle local refs when getDeferBlocks is invoked in tests (#52973) 2023-11-16 12:20:54 -08:00