perf(react-query): Batch hydration notifications - #11229
Conversation
Hydrating several observed queries schedules a separate notification flush for each query. Wrap each HydrationBoundary hydrate pass in a notifyManager transaction so those callbacks flush together. Co-Authored-By: Codex <noreply@openai.com>
|
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 (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesReact hydration batching
Estimated code review effort: 1 (Trivial) | ~3 minutes Merge Risk: ⚪ Minimal · up to This localized change batches React hydration notifications to reduce redundant flushes without changing the hydration API; no actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
Suggested labels: 🚥 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 |
|
i'm not really sold on the safety of this one and i don't use nextjs |
HydrationBoundary is the manual React SSR bridge used by Next.js and custom integrations to merge dehydrated server data into the browser QueryClient. The main case this improves is a later dehydrated payload updating queries that already exist and have active observers, such as a client navigation.
Right now each updated query schedules its own notification flush. Wrapping each HydrationBoundary hydrate pass in notifyManager.batch keeps every observer callback, but flushes the scheduled callbacks together. For N observed queries, scheduled flushes drop from N to 1 without adding another scheduler tick.
This only changes @tanstack/react-query HydrationBoundary. The official @tanstack/react-router-ssr-query integration used by TanStack Start calls the core hydrate API directly, so that path is not affected by this PR.
The benchmark hydrates existing queries with active QueryObserver subscriptions through notifyManager.batchCalls, matching the React subscription path.
Vitest benchmark
Summary by CodeRabbit