File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
packages/vue-query-nuxt/src/runtime Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1- import type { DehydratedState } from "@tanstack/vue-query"
1+ import type { DehydratedState , DehydrateOptions } from "@tanstack/vue-query"
22import { QueryClient , VueQueryPlugin , dehydrate , hydrate } from "@tanstack/vue-query"
3- import { getVueQueryOptions } from "./utils"
3+ import { getVueQueryOptions , dehydrateOptionKeys } from "./utils"
44import { pluginHook } from "#build/internal.vue-query-plugin-hook"
55import { defineNuxtPlugin , useRuntimeConfig , useState } from "#imports"
66
@@ -16,7 +16,15 @@ export default defineNuxtPlugin((nuxt) => {
1616
1717 if ( import . meta. server ) {
1818 nuxt . hooks . hook ( "app:rendered" , ( ) => {
19- vueQueryState . value = dehydrate ( queryClient , dehydrateOptions )
19+ vueQueryState . value = dehydrate ( queryClient , dehydrateOptionKeys . reduce < DehydrateOptions > ( ( newDehydrateOptions , key ) => {
20+ if ( dehydrateOptions [ key ] !== undefined ) {
21+ // https://stackoverflow.com/questions/64408632/typescript-inconsistent-check-for-undefined-why-do-i-need-an-exclamation-poin
22+ // https://stackoverflow.com/questions/60077761/typescript-null-check-doesnt-work-inside-array-map-function/60077855#60077855
23+ const narrowedValue = dehydrateOptions [ key ]
24+ newDehydrateOptions [ key ] = ( ) => narrowedValue
25+ }
26+ return newDehydrateOptions
27+ } , { } ) )
2028 } )
2129 }
2230
Original file line number Diff line number Diff line change @@ -15,12 +15,13 @@ const composables = [
1515] as const
1616
1717type VueQueryComposables = typeof composables
18+ export const dehydrateOptionKeys = [ 'shouldDehydrateMutation' , 'shouldDehydrateQuery' , 'shouldRedactErrors' ] as Array < keyof DehydrateOptions > ;
1819export interface ModuleOptions {
1920 stateKey : string
2021 autoImports : VueQueryComposables | false
2122 queryClientOptions : QueryClientConfig | undefined
2223 vueQueryPluginOptions : VueQueryPluginOptions ,
23- dehydrateOptions : DehydrateOptions
24+ dehydrateOptions : { [ P in typeof dehydrateOptionKeys [ number ] ] ?: boolean }
2425}
2526
2627export const defaults : ModuleOptions = {
You can’t perform that action at this time.
0 commit comments