fix(query-core): handle combine throwing in QueriesObserver notify#10137
fix(query-core): handle combine throwing in QueriesObserver notify#10137veeceey wants to merge 1 commit intoTanStack:mainfrom
Conversation
When useSuspenseQueries is used with combine and a query transitions to pending/error state (e.g. after resetQueries), the combine function throws because data is undefined despite types narrowing it as defined. The #notify method calls combine as an optimization to check if the combined result changed. If combine throws during this check, we now catch the error and still notify listeners so the framework can re-suspend or show an error boundary. Fixes TanStack#10129
|
📝 WalkthroughWalkthroughThe changes add error handling to the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
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 #10129
When
useSuspenseQueriesis used withcombine, the types narrowdatato always be defined. But if a query transitions back to pending/error state (e.g. viaqueryClient.resetQueries()), thecombinefunction gets called with results wheredataisundefined, causing a runtime TypeError.This happens because
QueriesObserver.#notify()callscombineas an optimization check — to see if the combined result changed before notifying listeners. The listeners themselves receive raw results (not the combined one), so the combine call is purely for deduplication.The fix wraps the combine call in a try/catch. If combine throws, we treat it as a change and notify listeners anyway. This lets the framework-level code (React Suspense / Error Boundary) handle the state transition properly.
Added a test that reproduces the exact scenario: subscribe to a
QueriesObserverwith a combine function that accessesdataproperties, let queries resolve, then callresetQueries— previously this would throw, now it correctly notifies listeners with the pending result.Summary by CodeRabbit
Bug Fixes
Tests