fix(examples/vue/nuxt3): guard hydrate() against a null dehydrated state - #11270
fix(examples/vue/nuxt3): guard hydrate() against a null dehydrated state#11270awdr74100 wants to merge 1 commit into
Conversation
query-core 5.102.1 (TanStack#11260) narrowed hydrate()'s second parameter from `unknown` to `Partial<DehydratedState>` and removed the function's internal runtime guard that used to bail out early on `typeof !== 'object' || === null`. This example's plugin still calls `hydrate(queryClient, vueQueryState.value)` unconditionally, where `vueQueryState` is typed `DehydratedState | null` and stays unset (falsy) whenever the server-side `app:rendered` hook never ran — e.g. routes with `ssr: false`, or purely client-rendered pages. Previously the library's own null check absorbed this; now it throws: TypeError: Cannot read properties of undefined (reading 'mutations') This restores the equivalent guard at the call site, matching the behavior `hydrate()` used to provide internally before 5.102.1.
|
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 (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe Nuxt 3 Vue Query plugin now hydrates only when dehydrated state exists. It captures that state during setup and uses the captured value in the ChangesNuxt hydration
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to The Nuxt example now skips hydration when no server state exists, preventing a null or undefined state crash while preserving hydration when state is present; no actionable merge-blocking risk remains. 🚥 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 |
Summary
packages/query-core'shydrate()changed behavior in 5.102.1 (#11260, "accept partial dehydrated state"): the second parameter went fromdehydratedState: unknowntodehydratedState: Partial<DehydratedState>, and the function's internal runtime guard was removed along with it:This
examples/vue/nuxt3plugin still callshydrate()unconditionally with a value that's typed (and can genuinely be)DehydratedState | null:vueQueryState.valuestaysundefined(Nuxt'suseStatedefault with no init) whenever the server-sideapp:renderedhook never ran for the current route — e.g.ssr: falseroutes, or a purely client-rendered page. Previouslyhydrate()'s own guard absorbed that case silently. On@tanstack/vue-query≥ 5.102.1 it now throws:I ran into this while bumping
@tanstack/vue-queryin a Nuxt 4 project and traced it back to the removed guard — this example (and presumably anyone who copied it, since the example itself is still pinned to^5.90.2and hasn't hit this yet) will hit the same crash once bumped past 5.102.1.What changed
Restores the equivalent guard at the call site, matching what
hydrate()used to do internally:(Captured into a local
constrather than a non-null assertion, since the truthiness narrowing onvueQueryState.valuedoesn't survive into the nested closure passed tonuxt.hooks.hook.)Notes
hydrate(client, state.value)pattern if that's wanted, just didn't want to guess at conventions across frameworks I haven't verified against.Summary by CodeRabbit