You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importtype{DehydratedState,VueQueryPluginOptions}from'@tanstack/vue-query'import{VueQueryPlugin,QueryClient,hydrate,dehydrate}from'@tanstack/vue-query'constpayloadKey='vue-query-statamic'exportdefaultdefineNuxtPlugin((nuxt)=>{constqueryClient=newQueryClient({defaultOptions: {queries: {staleTime: Infinity,// queries should never be stale until manually invalidated},},})constoptions: VueQueryPluginOptions={ queryClient }nuxt.vueApp.use(VueQueryPlugin,options)if(import.meta.server){nuxt.hooks.hook('app:rendered',()=>{nuxt.payload.data[payloadKey]=dehydrate(queryClient)})}if(import.meta.client){lethydratedState=nuxt.payload.data[payloadKey]asDehydratedState|undefinedhydrate(queryClient,hydratedState)useRouter().beforeResolve(()=>{conststate=nuxt.static.data[payloadKey]asDehydratedState|undefinedif(state&&state!==hydratedState){hydrate(queryClient,state)hydratedState=state}})}return{provide: {
queryClient,},}})
Works like a charm but the question is: are we missing some downside with this approach?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
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