@trpc/tanstack-react-query 11.18.1-canary.6 → 11.19.0

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.
@@ -12,7 +12,7 @@ import type {
12
12
  TRPCQueryKey,
13
13
  TRPCQueryOptionsResult,
14
14
  } from './types';
15
- import { createTRPCOptionsResult, readQueryKey } from './utils';
15
+ import { createTRPCOptionsResult } from './utils';
16
16
 
17
17
  interface BaseTRPCSubscriptionOptionsIn<TOutput, TError> {
18
18
  enabled?: boolean;
@@ -33,7 +33,9 @@ interface TRPCSubscriptionOptionsOut<
33
33
  TOutput,
34
34
  TError,
35
35
  TFeatureFlags extends FeatureFlags,
36
- > extends UnusedSkipTokenTRPCSubscriptionOptionsIn<TOutput, TError>,
36
+ >
37
+ extends
38
+ UnusedSkipTokenTRPCSubscriptionOptionsIn<TOutput, TError>,
37
39
  TRPCQueryOptionsResult {
38
40
  enabled: boolean;
39
41
  queryKey: TRPCQueryKey<TFeatureFlags['keyPrefix']>;
@@ -70,10 +72,7 @@ export interface TRPCSubscriptionOptions<
70
72
  >;
71
73
  }
72
74
  export type TRPCSubscriptionStatus =
73
- | 'idle'
74
- | 'connecting'
75
- | 'pending'
76
- | 'error';
75
+ 'idle' | 'connecting' | 'pending' | 'error';
77
76
 
78
77
  export interface TRPCSubscriptionBaseResult<TOutput, TError> {
79
78
  status: TRPCSubscriptionStatus;
@@ -85,29 +84,35 @@ export interface TRPCSubscriptionBaseResult<TOutput, TError> {
85
84
  reset: () => void;
86
85
  }
87
86
 
88
- export interface TRPCSubscriptionIdleResult<TOutput>
89
- extends TRPCSubscriptionBaseResult<TOutput, null> {
87
+ export interface TRPCSubscriptionIdleResult<
88
+ TOutput,
89
+ > extends TRPCSubscriptionBaseResult<TOutput, null> {
90
90
  status: 'idle';
91
91
  data: undefined;
92
92
  error: null;
93
93
  }
94
94
 
95
- export interface TRPCSubscriptionConnectingResult<TOutput, TError>
96
- extends TRPCSubscriptionBaseResult<TOutput, TError> {
95
+ export interface TRPCSubscriptionConnectingResult<
96
+ TOutput,
97
+ TError,
98
+ > extends TRPCSubscriptionBaseResult<TOutput, TError> {
97
99
  status: 'connecting';
98
100
  data: undefined | TOutput;
99
101
  error: TError | null;
100
102
  }
101
103
 
102
- export interface TRPCSubscriptionPendingResult<TOutput>
103
- extends TRPCSubscriptionBaseResult<TOutput, undefined> {
104
+ export interface TRPCSubscriptionPendingResult<
105
+ TOutput,
106
+ > extends TRPCSubscriptionBaseResult<TOutput, undefined> {
104
107
  status: 'pending';
105
108
  data: TOutput | undefined;
106
109
  error: null;
107
110
  }
108
111
 
109
- export interface TRPCSubscriptionErrorResult<TOutput, TError>
110
- extends TRPCSubscriptionBaseResult<TOutput, TError> {
112
+ export interface TRPCSubscriptionErrorResult<
113
+ TOutput,
114
+ TError,
115
+ > extends TRPCSubscriptionBaseResult<TOutput, TError> {
111
116
  status: 'error';
112
117
  data: TOutput | undefined;
113
118
  error: TError;
@@ -135,16 +140,24 @@ export const trpcSubscriptionOptions = <
135
140
  subscribe: typeof TRPCUntypedClient.prototype.subscription;
136
141
  path: string[];
137
142
  queryKey: TRPCQueryKey<TFeatureFlags['keyPrefix']>;
143
+ /**
144
+ * The raw input before queryKey serialization. Required to correctly detect
145
+ * `skipToken` because `getQueryKeyInternal` strips it from the queryKey args.
146
+ */
147
+ input: unknown;
138
148
  opts?: AnyTRPCSubscriptionOptionsIn;
139
149
  }): AnyTRPCSubscriptionOptionsOut<TFeatureFlags> => {
140
- const { subscribe, path, queryKey, opts = {} } = args;
141
- const input = readQueryKey(queryKey)?.args?.input;
150
+ const { subscribe, path, queryKey, input, opts = {} } = args;
142
151
  const enabled = 'enabled' in opts ? !!opts.enabled : input !== skipToken;
143
152
 
144
153
  const _subscribe: ReturnType<
145
154
  TRPCSubscriptionOptions<any, TFeatureFlags>
146
155
  >['subscribe'] = (innerOpts) => {
147
- return subscribe(path.join('.'), input ?? undefined, innerOpts);
156
+ return subscribe(
157
+ path.join('.'),
158
+ input === skipToken ? undefined : input,
159
+ innerOpts,
160
+ );
148
161
  };
149
162
 
150
163
  return {
@@ -237,7 +250,6 @@ export function useSubscription<TOutput, TError>(
237
250
  currentSubscriptionRef.current = () => {
238
251
  subscription.unsubscribe();
239
252
  };
240
- // eslint-disable-next-line react-hooks/react-compiler
241
253
  // eslint-disable-next-line react-hooks/exhaustive-deps
242
254
  }, [hashKey(opts.queryKey), opts.enabled]);
243
255
 
@@ -103,8 +103,7 @@ export type TRPCQueryKey<TPrefixEnabled extends boolean = false> =
103
103
  : TRPCQueryKeyWithoutPrefix;
104
104
 
105
105
  export type AnyTRPCQueryKey =
106
- | TRPCQueryKeyWithoutPrefix
107
- | TRPCQueryKeyWithPrefix;
106
+ TRPCQueryKeyWithoutPrefix | TRPCQueryKeyWithPrefix;
108
107
 
109
108
  /**
110
109
  * @public
@@ -120,8 +119,7 @@ export type TRPCMutationKeyWithPrefix = [
120
119
  export type TRPCMutationKeyWithoutPrefix = [path: string[]];
121
120
 
122
121
  export type AnyTRPCMutationKey =
123
- | TRPCMutationKeyWithoutPrefix
124
- | TRPCMutationKeyWithPrefix;
122
+ TRPCMutationKeyWithoutPrefix | TRPCMutationKeyWithPrefix;
125
123
 
126
124
  /**
127
125
  * @public