Repository navigation
Closed
Labels
comp: ssrServer-side rendering, hydration, @angular/ssr interop.Server-side rendering, hydration, @angular/ssr interop.comp: zonesChange detection / zone.js / zoneless.Change detection / zone.js / zoneless.type: featureNew capability or enhancement.New capability or enhancement.version: current (v17+)Targets the current modular API (v17+).Targets the current modular API (v17+).
Milestone
Description
Version info
Angular: 22.2
Firebase: 12.19.0
AngularFire: 22.0.0-rc.0, and main
Description
Every callback-taking read that holds a pending task keeps it one setTimeout(fn, 0) delay longer than it needs to:
ɵzoneWrapregisters a pending task when a function wrapped withblockUntilFirsttrue, such asonSnapshot,onAuthStateChangedoronValue, is handed a callback, and removes it withsetTimeout(taskDone, 0)scheduled right before the first callback runs (src/zones.ts:123) and again when the returned unsubscribe is called (:190).- So
ApplicationRef.isStablecan turn true only after that timer callback has run, one macrotask after the first value arrived. The comment next to the wrapping call,// TODO create a microtask to track callback functions(:153), asks for a microtask in its place. - feat(zones)!: deliver Observable read values as microtasks #3833 moved the Observable-returning reads off their timer. The callback reads are the remaining branch.
- Removing the task in a
finallyright after the callback body needs no timer and keeps a throwing callback from leaving its task behind.
How to reproduce these conditions
On a fresh Angular 22.2 app with @angular/fire@next, wrap a callback-taking function with the real ɵzoneWrap, invoke the callback from a setTimeout(fn, 0) outside Angular, and inside that same setTimeout callback, before invoking it, register a second setTimeout(fn, 0) and a queueMicrotask as markers. Observe the moment the wrapper calls the remover function that PendingTasks.add() returned:
- The marker
setTimeoutcallback has already run, in a zone.js app and a zoneless one, in Chrome and Firefox, for the first callback and for unsubscribe. - With the task removed in a
finallyafter the callback body, the remover is called before either marker has run, in every one of those runs. - The real
onSnapshotagainst the Firestore emulator, with the markers registered by a raw SDK listener attached first to the same document, reads the same way: the remover runs after the markersetTimeoutcallback today, and before it with the change.
Expected behavior
A callback read's pending task is removed as soon as its first callback has run, or as soon as it is unsubscribed.
Actual behavior
The task is removed one setTimeout(fn, 0) delay later.
Metadata
Metadata
Assignees
Labels
comp: ssrServer-side rendering, hydration, @angular/ssr interop.Server-side rendering, hydration, @angular/ssr interop.comp: zonesChange detection / zone.js / zoneless.Change detection / zone.js / zoneless.type: featureNew capability or enhancement.New capability or enhancement.version: current (v17+)Targets the current modular API (v17+).Targets the current modular API (v17+).
Activity
docs: describe the callback pending-task change in the v22 upgrade guide