File tree 2 files changed +13
-4
lines changed
packages/vue-query-nuxt/src/runtime 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"
2
2
import { QueryClient , VueQueryPlugin , dehydrate , hydrate } from "@tanstack/vue-query"
3
- import { getVueQueryOptions } from "./utils"
3
+ import { getVueQueryOptions , dehydrateOptionKeys } from "./utils"
4
4
import { pluginHook } from "#build/internal.vue-query-plugin-hook"
5
5
import { defineNuxtPlugin , useRuntimeConfig , useState } from "#imports"
6
6
@@ -16,7 +16,15 @@ export default defineNuxtPlugin((nuxt) => {
16
16
17
17
if ( import . meta. server ) {
18
18
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
+ } , { } ) )
20
28
} )
21
29
}
22
30
Original file line number Diff line number Diff line change @@ -15,12 +15,13 @@ const composables = [
15
15
] as const
16
16
17
17
type VueQueryComposables = typeof composables
18
+ export const dehydrateOptionKeys = [ 'shouldDehydrateMutation' , 'shouldDehydrateQuery' , 'shouldRedactErrors' ] as Array < keyof DehydrateOptions > ;
18
19
export interface ModuleOptions {
19
20
stateKey : string
20
21
autoImports : VueQueryComposables | false
21
22
queryClientOptions : QueryClientConfig | undefined
22
23
vueQueryPluginOptions : VueQueryPluginOptions ,
23
- dehydrateOptions : DehydrateOptions
24
+ dehydrateOptions : { [ P in typeof dehydrateOptionKeys [ number ] ] ?: boolean }
24
25
}
25
26
26
27
export const defaults : ModuleOptions = {
You can’t perform that action at this time.
0 commit comments