diff --git a/playground/pages/reactive.vue b/playground/pages/reactive.vue new file mode 100644 index 0000000..fe4ab5d --- /dev/null +++ b/playground/pages/reactive.vue @@ -0,0 +1,29 @@ + + + diff --git a/src/client/index.ts b/src/client/index.ts index 1a8ca4e..b4e0d3e 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -4,7 +4,7 @@ import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared' import { hash } from 'ohash' import { type DecoratedProcedureRecord } from './types' // @ts-expect-error: Nuxt auto-imports -import { getCurrentInstance, onScopeDispose, useAsyncData } from '#imports' +import { getCurrentInstance, onScopeDispose, useAsyncData, unref } from '#imports' /** * Calculates the key used for `useAsyncData` call. @@ -54,8 +54,8 @@ export function createNuxtProxyDecoration (name: stri controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController } - const queryKey = getQueryKey(path, input) - return useAsyncData(queryKey, () => (client as any)[path].query(input, { + const queryKey = getQueryKey(path, unref(input)) + return useAsyncData(queryKey, () => (client as any)[path].query(unref(input), { signal: controller?.signal, ...trpc }), asyncDataOptions) diff --git a/src/client/types.ts b/src/client/types.ts index 359857b..177336f 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -19,6 +19,7 @@ import type { KeysOf, PickFrom, } from 'nuxt/dist/app/composables/asyncData' +import type { Ref } from 'vue' interface TRPCRequestOptions extends _TRPCRequestOptions { abortOnUnmount?: boolean @@ -44,6 +45,8 @@ type SubscriptionResolver< ] ) => Unsubscribable +type MaybeRef = T | Ref + type DecorateProcedure< TProcedure extends AnyProcedure, TRouter extends AnyRouter, @@ -55,7 +58,7 @@ type DecorateProcedure< DataT = ResT, PickKeys extends KeysOf = KeysOf, >( - input: inferProcedureInput, + input: MaybeRef>, opts?: AsyncDataOptions & { trpc?: TRPCRequestOptions }, ) => AsyncData, DataE>, query: Resolver