@trpc/client 11.0.0-rc.522 → 11.0.0-rc.528

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.
@@ -1,20 +1,20 @@
1
1
  {
2
- "bundleSize": 52661,
3
- "bundleOrigSize": 70097,
4
- "bundleReduction": 24.87,
2
+ "bundleSize": 52387,
3
+ "bundleOrigSize": 69892,
4
+ "bundleReduction": 25.05,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/links/wsLink.ts",
8
- "size": 13710,
9
- "origSize": 15265,
8
+ "size": 13436,
9
+ "origSize": 15060,
10
10
  "renderedExports": [
11
11
  "createWSClient",
12
12
  "wsLink"
13
13
  ],
14
14
  "removedExports": [],
15
15
  "dependents": [],
16
- "percent": 26.03,
17
- "reduction": 10.19
16
+ "percent": 25.65,
17
+ "reduction": 10.78
18
18
  },
19
19
  {
20
20
  "id": "/src/links/httpBatchStreamLink.ts",
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "removedExports": [],
27
27
  "dependents": [],
28
- "percent": 11.13,
28
+ "percent": 11.19,
29
29
  "reduction": 3.51
30
30
  },
31
31
  {
@@ -37,7 +37,7 @@
37
37
  ],
38
38
  "removedExports": [],
39
39
  "dependents": [],
40
- "percent": 10.36,
40
+ "percent": 10.42,
41
41
  "reduction": 18.48
42
42
  },
43
43
  {
@@ -56,12 +56,12 @@
56
56
  ],
57
57
  "removedExports": [],
58
58
  "dependents": [
59
- "/src/links/httpBatchLink.ts",
60
59
  "/src/links/httpLink.ts",
60
+ "/src/links/httpBatchLink.ts",
61
61
  "/src/links/httpBatchStreamLink.ts",
62
62
  "/src/links/httpSubscriptionLink.ts"
63
63
  ],
64
- "percent": 8.48,
64
+ "percent": 8.52,
65
65
  "reduction": 32.82
66
66
  },
67
67
  {
@@ -76,7 +76,7 @@
76
76
  "/src/links/httpBatchLink.ts",
77
77
  "/src/links/httpBatchStreamLink.ts"
78
78
  ],
79
- "percent": 7.76,
79
+ "percent": 7.8,
80
80
  "reduction": 5.64
81
81
  },
82
82
  {
@@ -88,7 +88,7 @@
88
88
  ],
89
89
  "removedExports": [],
90
90
  "dependents": [],
91
- "percent": 7.45,
91
+ "percent": 7.49,
92
92
  "reduction": 4.69
93
93
  },
94
94
  {
@@ -100,7 +100,7 @@
100
100
  ],
101
101
  "removedExports": [],
102
102
  "dependents": [],
103
- "percent": 7.23,
103
+ "percent": 7.26,
104
104
  "reduction": 9.86
105
105
  },
106
106
  {
@@ -112,7 +112,7 @@
112
112
  ],
113
113
  "removedExports": [],
114
114
  "dependents": [],
115
- "percent": 6.05,
115
+ "percent": 6.08,
116
116
  "reduction": 14.15
117
117
  },
118
118
  {
@@ -127,7 +127,7 @@
127
127
  "/src/createTRPCUntypedClient.ts",
128
128
  "/src/createTRPCClient.ts"
129
129
  ],
130
- "percent": 4.11,
130
+ "percent": 4.13,
131
131
  "reduction": 47.6
132
132
  },
133
133
  {
@@ -140,14 +140,14 @@
140
140
  "removedExports": [],
141
141
  "dependents": [
142
142
  "/src/index.ts",
143
- "/src/links/httpBatchLink.ts",
144
143
  "/src/links/httpLink.ts",
144
+ "/src/links/httpBatchLink.ts",
145
145
  "/src/links/wsLink.ts",
146
146
  "/src/links/httpBatchStreamLink.ts",
147
147
  "/src/links/httpSubscriptionLink.ts",
148
148
  "/src/internals/TRPCUntypedClient.ts"
149
149
  ],
150
- "percent": 3.68,
150
+ "percent": 3.7,
151
151
  "reduction": 45.43
152
152
  },
153
153
  {
@@ -164,7 +164,7 @@
164
164
  "dependents": [
165
165
  "/src/index.ts"
166
166
  ],
167
- "percent": 2.25,
167
+ "percent": 2.27,
168
168
  "reduction": 73.19
169
169
  },
170
170
  {
@@ -179,7 +179,7 @@
179
179
  "/src/links/splitLink.ts",
180
180
  "/src/internals/TRPCUntypedClient.ts"
181
181
  ],
182
- "percent": 1.31,
182
+ "percent": 1.32,
183
183
  "reduction": 32.75
184
184
  },
185
185
  {
@@ -205,7 +205,7 @@
205
205
  "dependents": [
206
206
  "/src/unstable-internals.ts"
207
207
  ],
208
- "percent": 1.07,
208
+ "percent": 1.08,
209
209
  "reduction": 66.75
210
210
  },
211
211
  {
@@ -220,7 +220,7 @@
220
220
  "/src/index.ts",
221
221
  "/src/links/internals/httpUtils.ts"
222
222
  ],
223
- "percent": 0.81,
223
+ "percent": 0.82,
224
224
  "reduction": 33.54
225
225
  },
226
226
  {
@@ -37,7 +37,7 @@ export interface RequestInitEsque {
37
37
  /**
38
38
  * Sets the request's signal.
39
39
  */
40
- signal?: AbortSignal | null;
40
+ signal?: AbortSignal | undefined;
41
41
  }
42
42
  /**
43
43
  * A subset of the standard ReadableStream properties needed by tRPC internally.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,EACjC,IAAI,CAAC,EAAE,WAAW,GAAG,gBAAgB,KAClC,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5B;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,GAAG,EAAE,GAAG,GAAG,MAAM,EACjB,IAAI,CAAC,EAAE,yBAAyB,KAC7B,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5B,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC;IAE3D;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEtD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,yBAAyB,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,yBAAyB,GAAG,sBAAsB,GAAG,IAAI,CAAC;IAC1E;;;;;OAKG;IACH,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,EACjC,IAAI,CAAC,EAAE,WAAW,GAAG,gBAAgB,KAClC,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5B;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,GAAG,EAAE,GAAG,GAAG,MAAM,EACjB,IAAI,CAAC,EAAE,yBAAyB,KAC7B,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5B,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC;IAE3D;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEtD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,yBAAyB,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,yBAAyB,GAAG,sBAAsB,GAAG,IAAI,CAAC;IAC1E;;;;;OAKG;IACH,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC"}
@@ -59,11 +59,10 @@ function createWSClient(opts) {
59
59
  startLazyDisconnectTimer();
60
60
  });
61
61
  }
62
- function tryReconnect(conn) {
62
+ function tryReconnect() {
63
63
  if (!!connectTimer) {
64
64
  return;
65
65
  }
66
- conn.state = 'connecting';
67
66
  const timeout = retryDelayFn(connectAttempt++);
68
67
  reconnectInMs(timeout);
69
68
  }
@@ -126,11 +125,32 @@ function createWSClient(opts) {
126
125
  state: 'connecting'
127
126
  };
128
127
  clearTimeout(lazyDisconnectTimer);
129
- const onError = (evt)=>{
128
+ const onCloseOrError = ()=>{
129
+ if (self.state === 'closed') {
130
+ return;
131
+ }
130
132
  self.state = 'closed';
131
- if (self === activeConnection) {
132
- tryReconnect(self);
133
+ if (activeConnection === self) {
134
+ // connection might have been replaced already
135
+ tryReconnect();
133
136
  }
137
+ for (const [key, req] of Object.entries(pendingRequests)){
138
+ if (req.connection !== self) {
139
+ continue;
140
+ }
141
+ // The connection was closed either unexpectedly or because of a reconnect
142
+ if (req.type === 'subscription') {
143
+ // Subscriptions will resume after we've reconnected
144
+ resumeSubscriptionOnReconnect(req);
145
+ } else {
146
+ // Queries and mutations will error if interrupted
147
+ delete pendingRequests[key];
148
+ req.callbacks.error?.(TRPCClientError.TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
149
+ }
150
+ }
151
+ };
152
+ const onError = (evt)=>{
153
+ onCloseOrError();
134
154
  opts.onError?.(evt);
135
155
  };
136
156
  run(async ()=>{
@@ -189,10 +209,12 @@ function createWSClient(opts) {
189
209
  }
190
210
  req.callbacks.next?.(data);
191
211
  if (self === activeConnection && req.connection !== activeConnection) {
192
- // gracefully replace old connection with this
193
- const oldConn = req.connection;
212
+ // gracefully replace old connection with a new connection
194
213
  req.connection = self;
195
- oldConn && closeIfNoPending(oldConn);
214
+ }
215
+ if (req.connection !== self) {
216
+ // the connection has been replaced
217
+ return;
196
218
  }
197
219
  if ('result' in data && data.result.type === 'data' && typeof data.result.id === 'string') {
198
220
  req.lastEventId = data.result.id;
@@ -215,36 +237,13 @@ function createWSClient(opts) {
215
237
  }
216
238
  });
217
239
  ws.addEventListener('close', ({ code })=>{
218
- if (self.state === 'open') {
240
+ const wasOpen = self.state === 'open';
241
+ onCloseOrError();
242
+ if (wasOpen) {
219
243
  opts.onClose?.({
220
244
  code
221
245
  });
222
246
  }
223
- self.state = 'closed';
224
- if (activeConnection === self) {
225
- // connection might have been replaced already
226
- tryReconnect(self);
227
- }
228
- for (const [key, req] of Object.entries(pendingRequests)){
229
- if (req.connection !== self) {
230
- continue;
231
- }
232
- if (self.state === 'closed') {
233
- // If the connection was closed, we just call `complete()` on the request
234
- delete pendingRequests[key];
235
- req.callbacks.complete?.();
236
- continue;
237
- }
238
- // The connection was closed either unexpectedly or because of a reconnect
239
- if (req.type === 'subscription') {
240
- // Subscriptions will resume after we've reconnected
241
- resumeSubscriptionOnReconnect(req);
242
- } else {
243
- // Queries and mutations will error if interrupted
244
- delete pendingRequests[key];
245
- req.callbacks.error?.(TRPCClientError.TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
246
- }
247
- }
248
247
  });
249
248
  }).catch(onError);
250
249
  return self;
@@ -57,11 +57,10 @@ function createWSClient(opts) {
57
57
  startLazyDisconnectTimer();
58
58
  });
59
59
  }
60
- function tryReconnect(conn) {
60
+ function tryReconnect() {
61
61
  if (!!connectTimer) {
62
62
  return;
63
63
  }
64
- conn.state = 'connecting';
65
64
  const timeout = retryDelayFn(connectAttempt++);
66
65
  reconnectInMs(timeout);
67
66
  }
@@ -124,11 +123,32 @@ function createWSClient(opts) {
124
123
  state: 'connecting'
125
124
  };
126
125
  clearTimeout(lazyDisconnectTimer);
127
- const onError = (evt)=>{
126
+ const onCloseOrError = ()=>{
127
+ if (self.state === 'closed') {
128
+ return;
129
+ }
128
130
  self.state = 'closed';
129
- if (self === activeConnection) {
130
- tryReconnect(self);
131
+ if (activeConnection === self) {
132
+ // connection might have been replaced already
133
+ tryReconnect();
131
134
  }
135
+ for (const [key, req] of Object.entries(pendingRequests)){
136
+ if (req.connection !== self) {
137
+ continue;
138
+ }
139
+ // The connection was closed either unexpectedly or because of a reconnect
140
+ if (req.type === 'subscription') {
141
+ // Subscriptions will resume after we've reconnected
142
+ resumeSubscriptionOnReconnect(req);
143
+ } else {
144
+ // Queries and mutations will error if interrupted
145
+ delete pendingRequests[key];
146
+ req.callbacks.error?.(TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
147
+ }
148
+ }
149
+ };
150
+ const onError = (evt)=>{
151
+ onCloseOrError();
132
152
  opts.onError?.(evt);
133
153
  };
134
154
  run(async ()=>{
@@ -187,10 +207,12 @@ function createWSClient(opts) {
187
207
  }
188
208
  req.callbacks.next?.(data);
189
209
  if (self === activeConnection && req.connection !== activeConnection) {
190
- // gracefully replace old connection with this
191
- const oldConn = req.connection;
210
+ // gracefully replace old connection with a new connection
192
211
  req.connection = self;
193
- oldConn && closeIfNoPending(oldConn);
212
+ }
213
+ if (req.connection !== self) {
214
+ // the connection has been replaced
215
+ return;
194
216
  }
195
217
  if ('result' in data && data.result.type === 'data' && typeof data.result.id === 'string') {
196
218
  req.lastEventId = data.result.id;
@@ -213,36 +235,13 @@ function createWSClient(opts) {
213
235
  }
214
236
  });
215
237
  ws.addEventListener('close', ({ code })=>{
216
- if (self.state === 'open') {
238
+ const wasOpen = self.state === 'open';
239
+ onCloseOrError();
240
+ if (wasOpen) {
217
241
  opts.onClose?.({
218
242
  code
219
243
  });
220
244
  }
221
- self.state = 'closed';
222
- if (activeConnection === self) {
223
- // connection might have been replaced already
224
- tryReconnect(self);
225
- }
226
- for (const [key, req] of Object.entries(pendingRequests)){
227
- if (req.connection !== self) {
228
- continue;
229
- }
230
- if (self.state === 'closed') {
231
- // If the connection was closed, we just call `complete()` on the request
232
- delete pendingRequests[key];
233
- req.callbacks.complete?.();
234
- continue;
235
- }
236
- // The connection was closed either unexpectedly or because of a reconnect
237
- if (req.type === 'subscription') {
238
- // Subscriptions will resume after we've reconnected
239
- resumeSubscriptionOnReconnect(req);
240
- } else {
241
- // Queries and mutations will error if interrupted
242
- delete pendingRequests[key];
243
- req.callbacks.error?.(TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
244
- }
245
- }
246
245
  });
247
246
  }).catch(onError);
248
247
  return self;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "11.0.0-rc.522+b99c8b036",
3
+ "version": "11.0.0-rc.528+32e6b1285",
4
4
  "description": "The tRPC client library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -76,10 +76,10 @@
76
76
  "!**/*.test.*"
77
77
  ],
78
78
  "peerDependencies": {
79
- "@trpc/server": "11.0.0-rc.522+b99c8b036"
79
+ "@trpc/server": "11.0.0-rc.528+32e6b1285"
80
80
  },
81
81
  "devDependencies": {
82
- "@trpc/server": "11.0.0-rc.522+b99c8b036",
82
+ "@trpc/server": "11.0.0-rc.528+32e6b1285",
83
83
  "@types/isomorphic-fetch": "^0.0.39",
84
84
  "@types/node": "^20.10.0",
85
85
  "eslint": "^8.57.0",
@@ -96,5 +96,5 @@
96
96
  "funding": [
97
97
  "https://trpc.io/sponsor"
98
98
  ],
99
- "gitHead": "b99c8b0367db909f38427700c58c186bb235c0d6"
99
+ "gitHead": "32e6b1285dd844776d323ae23fbea638312d676e"
100
100
  }
@@ -49,7 +49,7 @@ export interface RequestInitEsque {
49
49
  /**
50
50
  * Sets the request's signal.
51
51
  */
52
- signal?: AbortSignal | null;
52
+ signal?: AbortSignal | undefined;
53
53
  }
54
54
 
55
55
  /**
@@ -177,12 +177,10 @@ export function createWSClient(opts: WebSocketClientOptions) {
177
177
  startLazyDisconnectTimer();
178
178
  });
179
179
  }
180
- function tryReconnect(conn: Connection) {
180
+ function tryReconnect() {
181
181
  if (!!connectTimer) {
182
182
  return;
183
183
  }
184
-
185
- conn.state = 'connecting';
186
184
  const timeout = retryDelayFn(connectAttempt++);
187
185
  reconnectInMs(timeout);
188
186
  }
@@ -253,11 +251,40 @@ export function createWSClient(opts: WebSocketClientOptions) {
253
251
 
254
252
  clearTimeout(lazyDisconnectTimer);
255
253
 
256
- const onError = (evt?: Event) => {
257
- self.state = 'closed';
258
- if (self === activeConnection) {
259
- tryReconnect(self);
254
+ const onCloseOrError = () => {
255
+ if (self.state === 'closed') {
256
+ return;
257
+ }
258
+
259
+ (self as Connection).state = 'closed';
260
+ if (activeConnection === self) {
261
+ // connection might have been replaced already
262
+ tryReconnect();
263
+ }
264
+
265
+ for (const [key, req] of Object.entries(pendingRequests)) {
266
+ if (req.connection !== self) {
267
+ continue;
268
+ }
269
+
270
+ // The connection was closed either unexpectedly or because of a reconnect
271
+ if (req.type === 'subscription') {
272
+ // Subscriptions will resume after we've reconnected
273
+ resumeSubscriptionOnReconnect(req);
274
+ } else {
275
+ // Queries and mutations will error if interrupted
276
+ delete pendingRequests[key];
277
+ req.callbacks.error?.(
278
+ TRPCClientError.from(
279
+ new TRPCWebSocketClosedError('WebSocket closed prematurely'),
280
+ ),
281
+ );
282
+ }
260
283
  }
284
+ };
285
+
286
+ const onError = (evt?: Event) => {
287
+ onCloseOrError();
261
288
  opts.onError?.(evt);
262
289
  };
263
290
  run(async () => {
@@ -328,10 +355,12 @@ export function createWSClient(opts: WebSocketClientOptions) {
328
355
 
329
356
  req.callbacks.next?.(data);
330
357
  if (self === activeConnection && req.connection !== activeConnection) {
331
- // gracefully replace old connection with this
332
- const oldConn = req.connection;
358
+ // gracefully replace old connection with a new connection
333
359
  req.connection = self;
334
- oldConn && closeIfNoPending(oldConn);
360
+ }
361
+ if (req.connection !== self) {
362
+ // the connection has been replaced
363
+ return;
335
364
  }
336
365
 
337
366
  if (
@@ -366,40 +395,11 @@ export function createWSClient(opts: WebSocketClientOptions) {
366
395
  });
367
396
 
368
397
  ws.addEventListener('close', ({ code }) => {
369
- if (self.state === 'open') {
370
- opts.onClose?.({ code });
371
- }
372
- self.state = 'closed';
398
+ const wasOpen = self.state === 'open';
399
+ onCloseOrError();
373
400
 
374
- if (activeConnection === self) {
375
- // connection might have been replaced already
376
- tryReconnect(self);
377
- }
378
-
379
- for (const [key, req] of Object.entries(pendingRequests)) {
380
- if (req.connection !== self) {
381
- continue;
382
- }
383
-
384
- if (self.state === 'closed') {
385
- // If the connection was closed, we just call `complete()` on the request
386
- delete pendingRequests[key];
387
- req.callbacks.complete?.();
388
- continue;
389
- }
390
- // The connection was closed either unexpectedly or because of a reconnect
391
- if (req.type === 'subscription') {
392
- // Subscriptions will resume after we've reconnected
393
- resumeSubscriptionOnReconnect(req);
394
- } else {
395
- // Queries and mutations will error if interrupted
396
- delete pendingRequests[key];
397
- req.callbacks.error?.(
398
- TRPCClientError.from(
399
- new TRPCWebSocketClosedError('WebSocket closed prematurely'),
400
- ),
401
- );
402
- }
401
+ if (wasOpen) {
402
+ opts.onClose?.({ code });
403
403
  }
404
404
  });
405
405
  }).catch(onError);