test(query-core/queryClient): add test for invalidated 'fetchQuery' resolving consistently#11054
test(query-core/queryClient): add test for invalidated 'fetchQuery' resolving consistently#11054ckdwns9121 wants to merge 1 commit into
Conversation
Cover the stale fetchQuery invalidation scenario with both active and inactive observers. Silent cancellation now follows the replacement fetch while inactive queries retain their original fetch, and both paths resolve to fresh data. Constraint: Preserve the silent cancellation contract introduced by TanStack#9293 Rejected: Force CancelledError rejection | current query-core behavior intentionally piggybacks replacement fetches Confidence: high Scope-risk: narrow Tested: query-core 548 tests; queryClient 109 tests; ESLint; TypeScript current; Prettier Not-tested: legacy TypeScript matrix due local Corepack pnpm.cjs EACCES Related: TanStack#8060
📝 WalkthroughWalkthroughAdded a parameterized ChangesInvalidateQueries fetchQuery behavior
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
View your CI Pipeline Execution ↗ for commit a1228a2
☁️ Nx Cloud last updated this comment at |
|
Thanks @ckdwns9121! Closing this one — I don't think it adds coverage we don't already have. The The Appreciate the effort though 🙏 |
Summary
fetchQuerycalls invalidated after fetching startsContext
Issue #8060 reported that
invalidateQueriescould make an imperativefetchQueryreject with a silentCancelledErroronly when an unrelated active observer existed.The cancellation changes merged in #9293 now intentionally make a silently cancelled fetch follow the replacement fetch promise. On current
main, the active-observer path starts a replacement fetch while the inactive path keeps its original fetch, but both consistently resolve with the updated data. This test locks that behavior against the original reproduction conditions.Validation
pnpm --filter @tanstack/query-core test:lib --run src/__tests__/queryClient.test.tsx(109 tests)pnpm --filter @tanstack/query-core test:lib --run(548 tests)pnpm --filter @tanstack/query-core test:eslint(0 errors; one pre-existing cspell warning)pnpm --filter @tanstack/query-core test:types:tscurrentpnpm prettier --write packages/query-core/src/__tests__/queryClient.test.tsxThe full legacy TypeScript matrix could not run locally because Corepack attempted to execute its cached
pnpm.cjsdirectly and returnedEACCES; the current TypeScript build and Vitest type checks pass.Summary by CodeRabbit