fix(react-query): add experimental_prefetchInRender support to useQueries#10218
fix(react-query): add experimental_prefetchInRender support to useQueries#10218isaackaara wants to merge 2 commits intoTanStack:mainfrom
Conversation
…ries useQueries did not implement the experimental_prefetchInRender option, causing React.use(promise) to never resolve when using useQueries instead of useQuery. This adds the same prefetchInRender logic from useBaseQuery to useQueries: for each query that has the option enabled and will fetch, it either triggers an optimistic fetch (new cache entry) or subscribes to the existing cache promise, then calls updateResult to finalize the thenable. Closes TanStack#9988
🦋 Changeset detectedLatest commit: 58ccf61 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoRun configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds client-side handling for experimental_prefetchInRender in useQueries: for optimistic results it locates the QueryObserver/Query from cache, triggers an optimistic fetch or subscribes to an existing cache promise (client-only), and updates observer results when the promise settles. Changes
Sequence Diagram(s)sequenceDiagram
participant Render as Client Render
participant Cache as Query Cache
participant Observer as QueryObserver
participant Query as Query (core)
Render->>Cache: find Query / QueryObserver for queryKey
alt query has no dataUpdateCount
Render->>Query: fetchOptimistic() (start fetch)
Query-->>Render: returns promise
else existing cache promise
Render->>Cache: subscribe to cache promise
Cache-->>Render: returns existing promise
end
Render->>Render: attach .catch(noop).finally(update observer result)
Render->>Observer: updateObserverResult() with new data
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Problem
experimental_prefetchInRenderworks withuseQuerybut not withuseQueries. When usingReact.use(promise)withuseQueries, the component never finishes loading because the promise never resolves.Root Cause
useBaseQueryimplementsexperimental_prefetchInRenderby detecting when a query will fetch and either:When the promise resolves, it calls
observer.updateResult()which finalizes thecurrentThenable.useQuerieswas missing this logic entirely — theexperimental_prefetchInRenderoption was ignored.Fix
Added the same prefetch-in-render logic to
useQueries, iterating over each query's result and options to handle theexperimental_prefetchInRenderflag individually. For each query that will fetch and has the option enabled:fetchOptimistic()immediatelyobserver.updateResult()is called to finalize the thenableCloses #9988
Summary by CodeRabbit
New Features
Chores