fix(angular-query): hold a pending task while a query subscription fetches - #11178
fix(angular-query): hold a pending task while a query subscription fetches#11178yogesh968 wants to merge 1 commit into
Conversation
…tches The pending task that keeps the application unstable was only registered from inside the observer subscription callback. That callback is batched through the notify manager, so it runs in a later task than the fetch it reports. Between subscribing and that first notification the application looks stable, which lets 'ApplicationRef.whenStable()' and 'fixture.whenStable()' resolve while the query is still loading. Register the task right after subscribing when the observer is already fetching, so the window is covered. Two existing tests awaited 'whenStable()' without letting the batched notification run, and only passed because of this gap. They now advance the timers while waiting, matching the other pending task tests.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAngular query integration now registers pending tasks when fetching starts, including cases where observer notifications are batched. Tests cover timer processing, Angular stability, and effect observation. A patch changeset documents the behavior. ChangesAngular pending-task flow
Estimated code review effort: 2 (Simple) | ~10 minutes Mergeability Score: ⚪ Minimal · up to The change keeps Angular pending-task tracking active during query startup and adds focused regression coverage; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #9981
Fixes #9910
Fixes #10046
The problem
createBaseQueryregisters the Angular pending task from inside the observer subscription callback:Subscribing is what starts the fetch, but the callback is batched through the notify manager, so it runs in a later task than the fetch it reports. In between there is no pending task, the application counts as stable, and
whenStable()resolves while the query is still loading.That is what the three linked issues run into. In a
TestBedtest the usualfixture.detectChanges()followed byawait fixture.whenStable()returns with the query stillpending,data()stillundefined, and anyeffect()readingisSuccess()never seeingtrue. The workaround people have landed on is an arbitrarysetTimeout(0)beforewhenStable(), which #10046 describes.The change
After subscribing, take the pending task straight away if the observer is already fetching. The release path is unchanged, so the task is still handed back on the first notification that reports
fetchStatus: 'idle'and on cleanup.Tests
Added a test to
pending-tasks.test.tsthat mounts a component the way the issues describe, with a template readingisSuccess()and aneffect()observing it, and asserts on the state afterfixture.whenStable(). It fails onmainand passes here.Two existing tests in
inject-query.test.tsawaitedwhenStable()without letting the batched notification run and only passed because of this gap. They now advance the timers while waiting, which is the pattern the rest ofpending-tasks.test.tsalready uses.Whole
@tanstack/angular-query-experimentalsuite is green: 219 tests.Summary by CodeRabbit
whenStable()waits for asynchronous query loading to finish, including batched or delayed notifications.