Replies: 2 comments 1 reply
This comment was marked as spam.
This comment was marked as spam.
|
In Nuxt 3 with ISR and payload extraction, Putting the dehydrated state into import { VueQueryPlugin, QueryClient, hydrate, dehydrate } from '@tanstack/vue-query'
import type { DehydratedState } from '@tanstack/vue-query'
export default defineNuxtPlugin((nuxtApp) => {
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 5, // 5 mins
},
},
})
nuxtApp.vueApp.use(VueQueryPlugin, { queryClient })
const payloadKey = 'vueQueryState'
if (import.meta.server) {
nuxtApp.hooks.hook('app:rendered', () => {
nuxtApp.payload[payloadKey] = dehydrate(queryClient)
})
}
if (import.meta.client) {
nuxtApp.hooks.hook('app:created', () => {
const state = nuxtApp.payload[payloadKey] as DehydratedState | undefined
if (state) {
hydrate(queryClient, state)
}
})
}
})Using the |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The docs describe integrating Tanstack Query via a plugin like this: https://tanstack.com/query/latest/docs/framework/vue/guides/ssr#nuxt-3
We have tried to integrate Vercel ISR in our project and ran into the issue that this only works on initial hydration. We do not benefit from the feature introduced in Nuxt 3.21.0 where navigation does hydrate the payload of the target site, as the Tanstack Query client state does only get dehydrated into the
__NUXT__payload on the bottom of the HTML, but not into the_payload.json.So instead, we are now putting the dehydrated state directly into the nuxt payload like this:
Works like a charm but the question is: are we missing some downside with this approach?
All reactions