Nuxt SSR hydration mismatch
Hello all,
Nuxt v4, tanstack query v5
I'm trying tanstack with nuxt, looks like SSR works well but I have an hydration mismtach
I followed this : https://tanstack.com/query/latest/docs/framework/vue/guides/ssr
My code :
The mismatch :

7 Replies
fascinating-indigoOPโข2w ago
Did I do anything wrong ^^" ?
Thanks ๐
if I remove the onServerPrefetch it works properly most of the time... still have it some time randomly but with comments inside
not sure what is the intended way ^^"
wise-whiteโข7d ago
You might want to check all items from this list, which is a list of common issues with hydration - https://nuxt.com/docs/3.x/guide/best-practices/hydration
fascinating-indigoOPโข7d ago
normally it's not a common issue, since it works with useFetch() without hydration issue (still checked to be sure ^^)
I can't reproduce it now... I'm wondering if it was just from HMR wizardries at that moment
If this is the right way to call it (without onServerPrefetch or dealing with suspense) I'm probably good to go I guess ^^
wise-whiteโข7d ago
Without
suspense
it might not work, as you are not waiting
for data to be fetched so it might be missing from initial page render, and actually fetch on the client (you might want to inspect the initial html sent to client to confirm).
You can use await suspense()
in onServerPrefetch
-> it will suspend while waiting for data only on server.
Or directly in setup
function -> it will suspend both on server and client if necessary.
Make sure that you do not have some kind of timestamp that might change between rendering on server
and client
, you wrapped this component in <Suspense>
and have correct staleTime
set to avoid refetching
on client.fascinating-indigoOPโข7d ago
Thanks a lot I'll check all that ๐
if i'm in
<script setup lang="ts">
in vue 3 it's considered as being in the setup() func right ?
I started at vue 3 and nuxt 3 so I'm not used to setup() func in the option API ^^"wise-whiteโข7d ago
If you run this example - https://github.com/TanStack/query/tree/main/examples/vue/nuxt3 you will see in devtools, that
api call
is not happening for the initial render and data is already included in initial html
- means suspense and SSR is working.
Yes <script setup>
is validfascinating-indigoOPโข7d ago
Perfect thanks ๐
as you said, I set up it right and the api call is indeed not happening and the data il already included.
works like a charm, I'm loving tanstack query a lot
thanks for your help