@trpc/react-query 11.0.0-alpha-tmp-app-router-example.388 → 11.0.0-alpha-tmp-issues-5851-take-two.448

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/bundle-analysis.json +47 -47
  2. package/dist/createTRPCReact.d.ts +5 -1
  3. package/dist/createTRPCReact.d.ts.map +1 -1
  4. package/dist/createTRPCReact.js +2 -1
  5. package/dist/createTRPCReact.mjs +2 -1
  6. package/dist/internals/getQueryKey.d.ts +2 -2
  7. package/dist/internals/getQueryKey.d.ts.map +1 -1
  8. package/dist/internals/useHookResult.d.ts +1 -1
  9. package/dist/internals/useHookResult.d.ts.map +1 -1
  10. package/dist/rsc.d.ts +17 -1
  11. package/dist/rsc.d.ts.map +1 -1
  12. package/dist/rsc.js +27 -9
  13. package/dist/rsc.mjs +27 -9
  14. package/dist/server/ssgProxy.d.ts.map +1 -1
  15. package/dist/server/ssgProxy.js +51 -51
  16. package/dist/server/ssgProxy.mjs +52 -52
  17. package/dist/shared/hooks/createHooksInternal.d.ts +6 -6
  18. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  19. package/dist/shared/hooks/createHooksInternal.js +1 -1
  20. package/dist/shared/hooks/createHooksInternal.mjs +2 -2
  21. package/dist/shared/proxy/decorationProxy.d.ts +1 -1
  22. package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
  23. package/dist/shared/proxy/decorationProxy.js +1 -2
  24. package/dist/shared/proxy/decorationProxy.mjs +1 -2
  25. package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
  26. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
  27. package/dist/shared/proxy/utilsProxy.js +6 -7
  28. package/dist/shared/proxy/utilsProxy.mjs +6 -7
  29. package/dist/shared/types.d.ts +0 -1
  30. package/dist/shared/types.d.ts.map +1 -1
  31. package/package.json +8 -8
  32. package/src/createTRPCReact.tsx +25 -8
  33. package/src/internals/getQueryKey.ts +2 -2
  34. package/src/internals/useHookResult.ts +1 -1
  35. package/src/rsc.tsx +28 -11
  36. package/src/server/ssgProxy.ts +50 -51
  37. package/src/shared/hooks/createHooksInternal.tsx +7 -7
  38. package/src/shared/proxy/decorationProxy.ts +2 -2
  39. package/src/shared/proxy/useQueriesProxy.ts +7 -5
  40. package/src/shared/proxy/utilsProxy.ts +11 -8
@@ -193,60 +193,59 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
193
193
  TRouter['_def']['record']
194
194
  >
195
195
  >;
196
+ const proxy = createRecursiveProxy<CreateSSGHelpers>((opts) => {
197
+ const args = opts.args;
198
+ const input = args[0];
199
+ const arrayPath = [...opts.path];
200
+ const utilName = arrayPath.pop() as keyof AnyDecoratedProcedure;
201
+
202
+ const queryFn = () =>
203
+ resolvedOpts.query({ path: arrayPath.join('.'), input });
204
+
205
+ const queryKey = getQueryKeyInternal(
206
+ arrayPath,
207
+ input,
208
+ getQueryType(utilName),
209
+ );
210
+
211
+ const helperMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
212
+ fetch: () => {
213
+ const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
214
+ return queryClient.fetchQuery({ ...args1, queryKey, queryFn });
215
+ },
216
+ fetchInfinite: () => {
217
+ const args1 = args[1] as Maybe<
218
+ TRPCFetchInfiniteQueryOptions<any, any, any>
219
+ >;
220
+ return queryClient.fetchInfiniteQuery({
221
+ ...args1,
222
+ queryKey,
223
+ queryFn,
224
+ initialPageParam: args1?.initialCursor ?? null,
225
+ });
226
+ },
227
+ prefetch: () => {
228
+ const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
229
+ return queryClient.prefetchQuery({ ...args1, queryKey, queryFn });
230
+ },
231
+ prefetchInfinite: () => {
232
+ const args1 = args[1] as Maybe<
233
+ TRPCFetchInfiniteQueryOptions<any, any, any>
234
+ >;
235
+ return queryClient.prefetchInfiniteQuery({
236
+ ...args1,
237
+ queryKey,
238
+ queryFn,
239
+ initialPageParam: args1?.initialCursor ?? null,
240
+ });
241
+ },
242
+ };
196
243
 
244
+ return helperMap[utilName]();
245
+ });
197
246
  return createFlatProxy<CreateSSGHelpers>((key) => {
198
247
  if (key === 'queryClient') return queryClient;
199
248
  if (key === 'dehydrate') return _dehydrate;
200
-
201
- return createRecursiveProxy((opts) => {
202
- const args = opts.args;
203
- const input = args[0];
204
- const arrayPath = [key, ...opts.path];
205
- const utilName = arrayPath.pop() as keyof AnyDecoratedProcedure;
206
-
207
- const queryFn = () =>
208
- resolvedOpts.query({ path: arrayPath.join('.'), input });
209
-
210
- const queryKey = getQueryKeyInternal(
211
- arrayPath,
212
- input,
213
- getQueryType(utilName),
214
- );
215
-
216
- const helperMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
217
- fetch: () => {
218
- const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
219
- return queryClient.fetchQuery({ ...args1, queryKey, queryFn });
220
- },
221
- fetchInfinite: () => {
222
- const args1 = args[1] as Maybe<
223
- TRPCFetchInfiniteQueryOptions<any, any, any>
224
- >;
225
- return queryClient.fetchInfiniteQuery({
226
- ...args1,
227
- queryKey,
228
- queryFn,
229
- initialPageParam: args1?.initialCursor ?? null,
230
- });
231
- },
232
- prefetch: () => {
233
- const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
234
- return queryClient.prefetchQuery({ ...args1, queryKey, queryFn });
235
- },
236
- prefetchInfinite: () => {
237
- const args1 = args[1] as Maybe<
238
- TRPCFetchInfiniteQueryOptions<any, any, any>
239
- >;
240
- return queryClient.prefetchInfiniteQuery({
241
- ...args1,
242
- queryKey,
243
- queryFn,
244
- initialPageParam: args1?.initialCursor ?? null,
245
- });
246
- },
247
- };
248
-
249
- return helperMap[utilName]();
250
- });
249
+ return proxy[key];
251
250
  });
252
251
  }
@@ -134,7 +134,7 @@ export function createRootHooks<
134
134
  }
135
135
 
136
136
  function useQuery(
137
- path: string[],
137
+ path: readonly string[],
138
138
  input: unknown,
139
139
  opts?: UseTRPCQueryOptions<unknown, unknown, TError>,
140
140
  ): UseTRPCQueryResult<unknown, TError> {
@@ -222,7 +222,7 @@ export function createRootHooks<
222
222
  }
223
223
 
224
224
  function useSuspenseQuery(
225
- path: string[],
225
+ path: readonly string[],
226
226
  input: unknown,
227
227
  opts?: UseTRPCSuspenseQueryOptions<unknown, unknown, TError>,
228
228
  ): UseTRPCSuspenseQueryResult<unknown, TError> {
@@ -261,7 +261,7 @@ export function createRootHooks<
261
261
  }
262
262
 
263
263
  function useMutation(
264
- path: string[],
264
+ path: readonly string[],
265
265
  opts?: UseTRPCMutationOptions<unknown, TError, unknown, unknown>,
266
266
  ): UseTRPCMutationResult<unknown, TError, unknown, unknown> {
267
267
  const { client } = useContext();
@@ -303,11 +303,11 @@ export function createRootHooks<
303
303
 
304
304
  /* istanbul ignore next -- @preserve */
305
305
  function useSubscription(
306
- path: string[],
306
+ path: readonly string[],
307
307
  input: unknown,
308
308
  opts: UseTRPCSubscriptionOptions<unknown, TError>,
309
309
  ) {
310
- const enabled = opts?.enabled ?? true;
310
+ const enabled = opts?.enabled ?? input !== skipToken;
311
311
  const queryKey = hashKey(getQueryKeyInternal(path, input, 'any'));
312
312
  const { client } = useContext();
313
313
 
@@ -349,7 +349,7 @@ export function createRootHooks<
349
349
  }
350
350
 
351
351
  function useInfiniteQuery(
352
- path: string[],
352
+ path: readonly string[],
353
353
  input: unknown,
354
354
  opts: UseTRPCInfiniteQueryOptions<unknown, unknown, TError>,
355
355
  ): UseTRPCInfiniteQueryResult<unknown, TError, unknown> {
@@ -423,7 +423,7 @@ export function createRootHooks<
423
423
  }
424
424
 
425
425
  function useSuspenseInfiniteQuery(
426
- path: string[],
426
+ path: readonly string[],
427
427
  input: unknown,
428
428
  opts: UseTRPCSuspenseInfiniteQueryOptions<unknown, unknown, TError>,
429
429
  ): UseTRPCSuspenseInfiniteQueryResult<unknown, TError, unknown> {
@@ -9,9 +9,9 @@ import type { CreateReactQueryHooks } from '../hooks/createHooksInternal';
9
9
  export function createReactDecoration<
10
10
  TRouter extends AnyRouter,
11
11
  TSSRContext = unknown,
12
- >(name: string, hooks: CreateReactQueryHooks<TRouter, TSSRContext>) {
12
+ >(hooks: CreateReactQueryHooks<TRouter, TSSRContext>) {
13
13
  return createRecursiveProxy(({ path, args }) => {
14
- const pathCopy = [name, ...path];
14
+ const pathCopy = [...path];
15
15
 
16
16
  // The last arg is for instance `.useMutation` or `.useQuery()`
17
17
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -88,7 +88,12 @@ export type UseSuspenseQueriesProcedureRecord<
88
88
  export function createUseQueries<TRouter extends AnyRouter>(
89
89
  client: TRPCUntypedClient<TRouter>,
90
90
  ) {
91
- return createRecursiveProxy((opts) => {
91
+ return createRecursiveProxy<
92
+ UseQueriesProcedureRecord<
93
+ TRouter['_def']['_config']['$types'],
94
+ TRouter['_def']['record']
95
+ >
96
+ >((opts) => {
92
97
  const arrayPath = opts.path;
93
98
  const dotPath = arrayPath.join('.');
94
99
  const [input, _opts] = opts.args as [
@@ -105,8 +110,5 @@ export function createUseQueries<TRouter extends AnyRouter>(
105
110
  };
106
111
 
107
112
  return options;
108
- }) as UseQueriesProcedureRecord<
109
- TRouter['_def']['_config']['$types'],
110
- TRouter['_def']['record']
111
- >;
113
+ });
112
114
  }
@@ -309,10 +309,9 @@ export const getQueryType = (
309
309
  */
310
310
  function createRecursiveUtilsProxy<TRouter extends AnyRouter>(
311
311
  context: TRPCQueryUtils<TRouter>,
312
- key: string,
313
312
  ) {
314
- return createRecursiveProxy((opts) => {
315
- const path = [key, ...opts.path];
313
+ return createRecursiveProxy<CreateQueryUtils<TRouter>>((opts) => {
314
+ const path = [...opts.path];
316
315
  const utilName = path.pop() as keyof AnyDecoratedProcedure;
317
316
  const args = [...opts.args] as Parameters<
318
317
  AnyDecoratedProcedure[typeof utilName]
@@ -355,16 +354,22 @@ export function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(
355
354
  ) {
356
355
  type CreateReactUtilsReturnType = CreateReactUtils<TRouter, TSSRContext>;
357
356
 
357
+ const clientProxy = createTRPCClientProxy(context.client);
358
+
359
+ const proxy = createRecursiveUtilsProxy(
360
+ context,
361
+ ) as CreateReactUtilsReturnType;
362
+
358
363
  return createFlatProxy<CreateReactUtilsReturnType>((key) => {
359
364
  const contextName = key as (typeof contextProps)[number];
360
365
  if (contextName === 'client') {
361
- return createTRPCClientProxy(context.client);
366
+ return clientProxy;
362
367
  }
363
368
  if (contextProps.includes(contextName)) {
364
369
  return context[contextName];
365
370
  }
366
371
 
367
- return createRecursiveUtilsProxy(context, key);
372
+ return proxy[key];
368
373
  });
369
374
  }
370
375
 
@@ -374,7 +379,5 @@ export function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(
374
379
  export function createQueryUtilsProxy<TRouter extends AnyRouter>(
375
380
  context: TRPCQueryUtils<TRouter>,
376
381
  ): CreateQueryUtils<TRouter> {
377
- return createFlatProxy((key) => {
378
- return createRecursiveUtilsProxy(context, key);
379
- });
382
+ return createRecursiveUtilsProxy(context);
380
383
  }