@tanstack/solid-query 5.30.0 → 5.30.1

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.
package/build/dev.cjs CHANGED
@@ -165,12 +165,18 @@ function createBaseQuery(options, Observer, queryClient) {
165
165
  unsubscribe = createClientSubscriber();
166
166
  }
167
167
  obs.updateResult();
168
+ if (observerResult.isError && !observerResult.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
169
+ observerResult.error,
170
+ obs.getCurrentQuery()
171
+ ])) {
172
+ setStateWithReconciliation(observerResult);
173
+ return reject(observerResult.error);
174
+ }
168
175
  if (!observerResult.isLoading) {
169
176
  const query = obs.getCurrentQuery();
170
- resolve(hydratableObserverResult(query, observerResult));
171
- } else {
172
- setStateWithReconciliation(observerResult);
177
+ return resolve(hydratableObserverResult(query, observerResult));
173
178
  }
179
+ setStateWithReconciliation(observerResult);
174
180
  });
175
181
  },
176
182
  {
@@ -257,20 +263,6 @@ function createBaseQuery(options, Observer, queryClient) {
257
263
  { defer: true }
258
264
  )
259
265
  );
260
- solidJs.createComputed(
261
- solidJs.on(
262
- () => state.status,
263
- () => {
264
- const obs = observer();
265
- if (state.isError && !state.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
266
- state.error,
267
- obs.getCurrentQuery()
268
- ])) {
269
- throw state.error;
270
- }
271
- }
272
- )
273
- );
274
266
  const handler = {
275
267
  get(target, prop) {
276
268
  if (prop === "data") {
package/build/dev.js CHANGED
@@ -164,12 +164,18 @@ function createBaseQuery(options, Observer, queryClient) {
164
164
  unsubscribe = createClientSubscriber();
165
165
  }
166
166
  obs.updateResult();
167
+ if (observerResult.isError && !observerResult.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
168
+ observerResult.error,
169
+ obs.getCurrentQuery()
170
+ ])) {
171
+ setStateWithReconciliation(observerResult);
172
+ return reject(observerResult.error);
173
+ }
167
174
  if (!observerResult.isLoading) {
168
175
  const query = obs.getCurrentQuery();
169
- resolve(hydratableObserverResult(query, observerResult));
170
- } else {
171
- setStateWithReconciliation(observerResult);
176
+ return resolve(hydratableObserverResult(query, observerResult));
172
177
  }
178
+ setStateWithReconciliation(observerResult);
173
179
  });
174
180
  },
175
181
  {
@@ -256,20 +262,6 @@ function createBaseQuery(options, Observer, queryClient) {
256
262
  { defer: true }
257
263
  )
258
264
  );
259
- createComputed(
260
- on(
261
- () => state.status,
262
- () => {
263
- const obs = observer();
264
- if (state.isError && !state.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
265
- state.error,
266
- obs.getCurrentQuery()
267
- ])) {
268
- throw state.error;
269
- }
270
- }
271
- )
272
- );
273
265
  const handler = {
274
266
  get(target, prop) {
275
267
  if (prop === "data") {
package/build/index.cjs CHANGED
@@ -165,12 +165,18 @@ function createBaseQuery(options, Observer, queryClient) {
165
165
  unsubscribe = createClientSubscriber();
166
166
  }
167
167
  obs.updateResult();
168
+ if (observerResult.isError && !observerResult.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
169
+ observerResult.error,
170
+ obs.getCurrentQuery()
171
+ ])) {
172
+ setStateWithReconciliation(observerResult);
173
+ return reject(observerResult.error);
174
+ }
168
175
  if (!observerResult.isLoading) {
169
176
  const query = obs.getCurrentQuery();
170
- resolve(hydratableObserverResult(query, observerResult));
171
- } else {
172
- setStateWithReconciliation(observerResult);
177
+ return resolve(hydratableObserverResult(query, observerResult));
173
178
  }
179
+ setStateWithReconciliation(observerResult);
174
180
  });
175
181
  },
176
182
  {
@@ -257,20 +263,6 @@ function createBaseQuery(options, Observer, queryClient) {
257
263
  { defer: true }
258
264
  )
259
265
  );
260
- solidJs.createComputed(
261
- solidJs.on(
262
- () => state.status,
263
- () => {
264
- const obs = observer();
265
- if (state.isError && !state.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
266
- state.error,
267
- obs.getCurrentQuery()
268
- ])) {
269
- throw state.error;
270
- }
271
- }
272
- )
273
- );
274
266
  const handler = {
275
267
  get(target, prop) {
276
268
  if (prop === "data") {
package/build/index.js CHANGED
@@ -164,12 +164,18 @@ function createBaseQuery(options, Observer, queryClient) {
164
164
  unsubscribe = createClientSubscriber();
165
165
  }
166
166
  obs.updateResult();
167
+ if (observerResult.isError && !observerResult.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
168
+ observerResult.error,
169
+ obs.getCurrentQuery()
170
+ ])) {
171
+ setStateWithReconciliation(observerResult);
172
+ return reject(observerResult.error);
173
+ }
167
174
  if (!observerResult.isLoading) {
168
175
  const query = obs.getCurrentQuery();
169
- resolve(hydratableObserverResult(query, observerResult));
170
- } else {
171
- setStateWithReconciliation(observerResult);
176
+ return resolve(hydratableObserverResult(query, observerResult));
172
177
  }
178
+ setStateWithReconciliation(observerResult);
173
179
  });
174
180
  },
175
181
  {
@@ -256,20 +262,6 @@ function createBaseQuery(options, Observer, queryClient) {
256
262
  { defer: true }
257
263
  )
258
264
  );
259
- createComputed(
260
- on(
261
- () => state.status,
262
- () => {
263
- const obs = observer();
264
- if (state.isError && !state.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
265
- state.error,
266
- obs.getCurrentQuery()
267
- ])) {
268
- throw state.error;
269
- }
270
- }
271
- )
272
- );
273
265
  const handler = {
274
266
  get(target, prop) {
275
267
  if (prop === "data") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-query",
3
- "version": "5.30.0",
3
+ "version": "5.30.1",
4
4
  "description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -2407,6 +2407,7 @@ describe('createQuery', () => {
2407
2407
 
2408
2408
  return (
2409
2409
  <div>
2410
+ <h1>{state.data}</h1>
2410
2411
  <h1>{state.status}</h1>
2411
2412
  <h2>{state.error?.message}</h2>
2412
2413
  </div>
@@ -2426,6 +2427,124 @@ describe('createQuery', () => {
2426
2427
  consoleMock.mockRestore()
2427
2428
  })
2428
2429
 
2430
+ it('should throw error inside the same component if queryFn throws and throwOnError is in use', async () => {
2431
+ const key = queryKey()
2432
+
2433
+ const consoleMock = vi
2434
+ .spyOn(console, 'error')
2435
+ .mockImplementation(() => undefined)
2436
+
2437
+ function Page() {
2438
+ const state = createQuery(() => ({
2439
+ queryKey: key,
2440
+ queryFn: () => Promise.reject(new Error('Error test')),
2441
+ retry: false,
2442
+ throwOnError: true,
2443
+ }))
2444
+
2445
+ return (
2446
+ <div>
2447
+ <ErrorBoundary fallback={() => <div>error boundary</div>}>
2448
+ <h1>{state.data}</h1>
2449
+ <h1>{state.status}</h1>
2450
+ <h2>{state.error?.message}</h2>
2451
+ </ErrorBoundary>
2452
+ </div>
2453
+ )
2454
+ }
2455
+
2456
+ const rendered = render(() => (
2457
+ <QueryClientProvider client={queryClient}>
2458
+ <Page />
2459
+ </QueryClientProvider>
2460
+ ))
2461
+
2462
+ await waitFor(() => rendered.getByText('error boundary'))
2463
+
2464
+ consoleMock.mockRestore()
2465
+ })
2466
+
2467
+ it('should throw error inside the same component if queryFn throws and show the correct error message', async () => {
2468
+ const key = queryKey()
2469
+
2470
+ const consoleMock = vi
2471
+ .spyOn(console, 'error')
2472
+ .mockImplementation(() => undefined)
2473
+
2474
+ function Page() {
2475
+ const state = createQuery(() => ({
2476
+ queryKey: key,
2477
+ queryFn: () => Promise.reject(new Error('Error test')),
2478
+ retry: false,
2479
+ throwOnError: true,
2480
+ }))
2481
+
2482
+ return (
2483
+ <div>
2484
+ <ErrorBoundary
2485
+ fallback={(err) => <div>Fallback error: {err.message}</div>}
2486
+ >
2487
+ <h1>{state.data}</h1>
2488
+ <h1>{state.status}</h1>
2489
+ <h2>{state.error?.message}</h2>
2490
+ </ErrorBoundary>
2491
+ </div>
2492
+ )
2493
+ }
2494
+
2495
+ const rendered = render(() => (
2496
+ <QueryClientProvider client={queryClient}>
2497
+ <Page />
2498
+ </QueryClientProvider>
2499
+ ))
2500
+
2501
+ await waitFor(() => rendered.getByText('Fallback error: Error test'))
2502
+
2503
+ consoleMock.mockRestore()
2504
+ })
2505
+
2506
+ it('should show the correct error message on the error property when accessed outside error boundary', async () => {
2507
+ const key = queryKey()
2508
+
2509
+ const consoleMock = vi
2510
+ .spyOn(console, 'error')
2511
+ .mockImplementation(() => undefined)
2512
+
2513
+ function Page() {
2514
+ const state = createQuery(() => ({
2515
+ queryKey: key,
2516
+ queryFn: () => Promise.reject(new Error('Error test')),
2517
+ retry: false,
2518
+ throwOnError: true,
2519
+ }))
2520
+
2521
+ return (
2522
+ <div>
2523
+ <h2>Outside error boundary: {state.error?.message}</h2>
2524
+ <ErrorBoundary
2525
+ fallback={(err) => <div>Fallback error: {err.message}</div>}
2526
+ >
2527
+ <h1>{state.data}</h1>
2528
+ <h1>{state.status}</h1>
2529
+ </ErrorBoundary>
2530
+ </div>
2531
+ )
2532
+ }
2533
+
2534
+ const rendered = render(() => (
2535
+ <QueryClientProvider client={queryClient}>
2536
+ <Page />
2537
+ </QueryClientProvider>
2538
+ ))
2539
+
2540
+ await waitFor(() =>
2541
+ rendered.getByText('Outside error boundary: Error test'),
2542
+ )
2543
+ await waitFor(() => rendered.getByText('Fallback error: Error test'))
2544
+
2545
+ consoleMock.mockRestore()
2546
+ })
2547
+
2429
2548
  it('should update with data if we observe no properties and throwOnError', async () => {
2430
2549
  const key = queryKey()
2431
2550
 
@@ -2491,7 +2610,7 @@ describe('createQuery', () => {
2491
2610
  const key = queryKey()
2492
2611
 
2493
2612
  function Page() {
2494
- const state = createQuery<unknown, Error>(() => ({
2613
+ const state = createQuery(() => ({
2495
2614
  queryKey: key,
2496
2615
  queryFn: () => Promise.reject(new Error('Remote Error')),
2497
2616
  retry: false,
@@ -2500,6 +2619,7 @@ describe('createQuery', () => {
2500
2619
 
2501
2620
  return (
2502
2621
  <div>
2622
+ <div>{state.data}</div>
2503
2623
  <h1>{state.status}</h1>
2504
2624
  <h2>{state.error?.message ?? ''}</h2>
2505
2625
  </div>
@@ -227,12 +227,24 @@ export function createBaseQuery<
227
227
  }
228
228
  obs.updateResult()
229
229
 
230
+ if (
231
+ observerResult.isError &&
232
+ !observerResult.isFetching &&
233
+ !isRestoring() &&
234
+ shouldThrowError(obs.options.throwOnError, [
235
+ observerResult.error,
236
+ obs.getCurrentQuery(),
237
+ ])
238
+ ) {
239
+ setStateWithReconciliation(observerResult)
240
+ return reject(observerResult.error)
241
+ }
230
242
  if (!observerResult.isLoading) {
231
243
  const query = obs.getCurrentQuery()
232
- resolve(hydratableObserverResult(query, observerResult))
233
- } else {
234
- setStateWithReconciliation(observerResult)
244
+ return resolve(hydratableObserverResult(query, observerResult))
235
245
  }
246
+
247
+ setStateWithReconciliation(observerResult)
236
248
  })
237
249
  },
238
250
  {
@@ -335,26 +347,6 @@ export function createBaseQuery<
335
347
  ),
336
348
  )
337
349
 
338
- createComputed(
339
- on(
340
- () => state.status,
341
- () => {
342
- const obs = observer()
343
- if (
344
- state.isError &&
345
- !state.isFetching &&
346
- !isRestoring() &&
347
- shouldThrowError(obs.options.throwOnError, [
348
- state.error,
349
- obs.getCurrentQuery(),
350
- ])
351
- ) {
352
- throw state.error
353
- }
354
- },
355
- ),
356
- )
357
-
358
350
  const handler = {
359
351
  get(
360
352
  target: QueryObserverResult<TData, TError>,