@tanstack/solid-query 4.14.3 → 4.15.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.
@@ -425,24 +425,28 @@ describe('useInfiniteQuery', () => {
425
425
  data: undefined,
426
426
  isFetching: true,
427
427
  isFetchingNextPage: false,
428
+ isRefetching: false,
428
429
  });
429
430
  // Initial fetch done
430
431
  expect(states[1]).toMatchObject({
431
432
  data: { pages: [10] },
432
433
  isFetching: false,
433
434
  isFetchingNextPage: false,
435
+ isRefetching: false,
434
436
  });
435
437
  // Fetch next page
436
438
  expect(states[2]).toMatchObject({
437
439
  data: { pages: [10] },
438
440
  isFetching: true,
439
441
  isFetchingNextPage: true,
442
+ isRefetching: false,
440
443
  });
441
444
  // Fetch next page done
442
445
  expect(states[3]).toMatchObject({
443
446
  data: { pages: [10, 11] },
444
447
  isFetching: false,
445
448
  isFetchingNextPage: false,
449
+ isRefetching: false,
446
450
  });
447
451
  // Fetch previous page
448
452
  expect(states[4]).toMatchObject({
@@ -450,6 +454,7 @@ describe('useInfiniteQuery', () => {
450
454
  isFetching: true,
451
455
  isFetchingNextPage: false,
452
456
  isFetchingPreviousPage: true,
457
+ isRefetching: false,
453
458
  });
454
459
  // Fetch previous page done
455
460
  expect(states[5]).toMatchObject({
@@ -457,6 +462,7 @@ describe('useInfiniteQuery', () => {
457
462
  isFetching: false,
458
463
  isFetchingNextPage: false,
459
464
  isFetchingPreviousPage: false,
465
+ isRefetching: false,
460
466
  });
461
467
  // Refetch
462
468
  expect(states[6]).toMatchObject({
@@ -464,6 +470,7 @@ describe('useInfiniteQuery', () => {
464
470
  isFetching: true,
465
471
  isFetchingNextPage: false,
466
472
  isFetchingPreviousPage: false,
473
+ isRefetching: true,
467
474
  });
468
475
  // Refetch done
469
476
  expect(states[7]).toMatchObject({
@@ -471,6 +478,7 @@ describe('useInfiniteQuery', () => {
471
478
  isFetching: false,
472
479
  isFetchingNextPage: false,
473
480
  isFetchingPreviousPage: false,
481
+ isRefetching: false,
474
482
  });
475
483
  });
476
484
  it('should be able to refetch when providing page params automatically', async () => {
@@ -514,24 +522,28 @@ describe('useInfiniteQuery', () => {
514
522
  data: undefined,
515
523
  isFetching: true,
516
524
  isFetchingNextPage: false,
525
+ isRefetching: false,
517
526
  });
518
527
  // Initial fetch done
519
528
  expect(states[1]).toMatchObject({
520
529
  data: { pages: [10] },
521
530
  isFetching: false,
522
531
  isFetchingNextPage: false,
532
+ isRefetching: false,
523
533
  });
524
534
  // Fetch next page
525
535
  expect(states[2]).toMatchObject({
526
536
  data: { pages: [10] },
527
537
  isFetching: true,
528
538
  isFetchingNextPage: true,
539
+ isRefetching: false,
529
540
  });
530
541
  // Fetch next page done
531
542
  expect(states[3]).toMatchObject({
532
543
  data: { pages: [10, 11] },
533
544
  isFetching: false,
534
545
  isFetchingNextPage: false,
546
+ isRefetching: false,
535
547
  });
536
548
  // Fetch previous page
537
549
  expect(states[4]).toMatchObject({
@@ -539,6 +551,7 @@ describe('useInfiniteQuery', () => {
539
551
  isFetching: true,
540
552
  isFetchingNextPage: false,
541
553
  isFetchingPreviousPage: true,
554
+ isRefetching: false,
542
555
  });
543
556
  // Fetch previous page done
544
557
  expect(states[5]).toMatchObject({
@@ -546,6 +559,7 @@ describe('useInfiniteQuery', () => {
546
559
  isFetching: false,
547
560
  isFetchingNextPage: false,
548
561
  isFetchingPreviousPage: false,
562
+ isRefetching: false,
549
563
  });
550
564
  // Refetch
551
565
  expect(states[6]).toMatchObject({
@@ -553,6 +567,7 @@ describe('useInfiniteQuery', () => {
553
567
  isFetching: true,
554
568
  isFetchingNextPage: false,
555
569
  isFetchingPreviousPage: false,
570
+ isRefetching: true,
556
571
  });
557
572
  // Refetch done
558
573
  expect(states[7]).toMatchObject({
@@ -560,6 +575,7 @@ describe('useInfiniteQuery', () => {
560
575
  isFetching: false,
561
576
  isFetchingNextPage: false,
562
577
  isFetchingPreviousPage: false,
578
+ isRefetching: false,
563
579
  });
564
580
  });
565
581
  it('should be able to refetch only specific pages when refetchPages is provided', async () => {
@@ -1759,38 +1759,6 @@ describe('createQuery', () => {
1759
1759
  expect(states[1]).toMatchObject({ isStale: false });
1760
1760
  expect(states[2]).toMatchObject({ isStale: true });
1761
1761
  });
1762
- it('should notify query cache when a query becomes stale', async () => {
1763
- const key = queryKey();
1764
- const states = [];
1765
- const fn = jest.fn();
1766
- const unsubscribe = queryCache.subscribe(fn);
1767
- function Page() {
1768
- const state = createQuery(key, () => 'test', {
1769
- staleTime: 10,
1770
- });
1771
- createRenderEffect(() => {
1772
- states.push({ ...state });
1773
- });
1774
- return null;
1775
- }
1776
- render(() => (<QueryClientProvider client={queryClient}>
1777
- <Page />
1778
- </QueryClientProvider>));
1779
- await sleep(20);
1780
- unsubscribe();
1781
- // 1. Query added -> loading
1782
- // 2. Observer result updated -> loading
1783
- // 3. Observer added
1784
- // 4. Query updated -> success
1785
- // 5. Observer result updated -> success
1786
- // 6. Query updated -> stale
1787
- // 7. Observer options updated
1788
- // 8. Observer result updated -> stale
1789
- // 9. Observer options updated
1790
- // Number 9 wont run in Solid JS
1791
- // Number 9 runs in react because the component re-renders after 8
1792
- expect(fn).toHaveBeenCalledTimes(8);
1793
- });
1794
1762
  it('should not re-render when it should only re-render on data changes and the data did not change', async () => {
1795
1763
  const key = queryKey();
1796
1764
  const states = [];
@@ -802,14 +802,16 @@
802
802
  this.queryHash = config.queryHash;
803
803
  this.initialState = config.state || getDefaultState$1(this.options);
804
804
  this.state = this.initialState;
805
- this.meta = config.meta;
805
+ }
806
+
807
+ get meta() {
808
+ return this.options.meta;
806
809
  }
807
810
 
808
811
  setOptions(options) {
809
812
  this.options = { ...this.defaultOptions,
810
813
  ...options
811
814
  };
812
- this.meta = options == null ? void 0 : options.meta;
813
815
  this.updateCacheTime(this.options.cacheTime);
814
816
  }
815
817
 
@@ -1039,8 +1041,7 @@
1039
1041
  options: this.options,
1040
1042
  queryKey: this.queryKey,
1041
1043
  state: this.state,
1042
- fetchFn,
1043
- meta: this.meta
1044
+ fetchFn
1044
1045
  };
1045
1046
  addSignalProperty(context);
1046
1047
  (_this$options$behavio = this.options.behavior) == null ? void 0 : _this$options$behavio.onFetch(context); // Store state in case the current fetch needs to be reverted
@@ -1274,8 +1275,7 @@
1274
1275
  queryHash,
1275
1276
  options: client.defaultQueryOptions(options),
1276
1277
  state,
1277
- defaultOptions: client.getQueryDefaults(queryKey),
1278
- meta: options.meta
1278
+ defaultOptions: client.getQueryDefaults(queryKey)
1279
1279
  });
1280
1280
  this.add(query);
1281
1281
  }
@@ -1381,11 +1381,14 @@
1381
1381
  this.logger = config.logger || defaultLogger;
1382
1382
  this.observers = [];
1383
1383
  this.state = config.state || getDefaultState();
1384
- this.meta = config.meta;
1385
1384
  this.updateCacheTime(this.options.cacheTime);
1386
1385
  this.scheduleGc();
1387
1386
  }
1388
1387
 
1388
+ get meta() {
1389
+ return this.options.meta;
1390
+ }
1391
+
1389
1392
  setState(state) {
1390
1393
  this.dispatch({
1391
1394
  type: 'setState',
@@ -1630,8 +1633,7 @@
1630
1633
  mutationId: ++this.mutationId,
1631
1634
  options: client.defaultMutationOptions(options),
1632
1635
  state,
1633
- defaultOptions: options.mutationKey ? client.getMutationDefaults(options.mutationKey) : undefined,
1634
- meta: options.meta
1636
+ defaultOptions: options.mutationKey ? client.getMutationDefaults(options.mutationKey) : undefined
1635
1637
  });
1636
1638
  this.add(mutation);
1637
1639
  return mutation;
@@ -1750,7 +1752,7 @@
1750
1752
  const queryFnContext = {
1751
1753
  queryKey: context.queryKey,
1752
1754
  pageParam: param,
1753
- meta: context.meta
1755
+ meta: context.options.meta
1754
1756
  };
1755
1757
  addSignalProperty(queryFnContext);
1756
1758
  const queryFnResult = queryFn(queryFnContext);
@@ -2759,6 +2761,10 @@
2759
2761
  return this.observers.map(observer => observer.getCurrentQuery());
2760
2762
  }
2761
2763
 
2764
+ getObservers() {
2765
+ return this.observers;
2766
+ }
2767
+
2762
2768
  getOptimisticResult(queries) {
2763
2769
  return this.findMatchingObservers(queries).map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions));
2764
2770
  }
@@ -2886,19 +2892,26 @@
2886
2892
  }
2887
2893
 
2888
2894
  createResult(query, options) {
2889
- var _state$data, _state$data2, _state$fetchMeta, _state$fetchMeta$fetc, _state$fetchMeta2, _state$fetchMeta2$fet;
2895
+ var _state$fetchMeta, _state$fetchMeta$fetc, _state$fetchMeta2, _state$fetchMeta2$fet, _state$data, _state$data2;
2890
2896
 
2891
2897
  const {
2892
2898
  state
2893
2899
  } = query;
2894
2900
  const result = super.createResult(query, options);
2901
+ const {
2902
+ isFetching,
2903
+ isRefetching
2904
+ } = result;
2905
+ const isFetchingNextPage = isFetching && ((_state$fetchMeta = state.fetchMeta) == null ? void 0 : (_state$fetchMeta$fetc = _state$fetchMeta.fetchMore) == null ? void 0 : _state$fetchMeta$fetc.direction) === 'forward';
2906
+ const isFetchingPreviousPage = isFetching && ((_state$fetchMeta2 = state.fetchMeta) == null ? void 0 : (_state$fetchMeta2$fet = _state$fetchMeta2.fetchMore) == null ? void 0 : _state$fetchMeta2$fet.direction) === 'backward';
2895
2907
  return { ...result,
2896
2908
  fetchNextPage: this.fetchNextPage,
2897
2909
  fetchPreviousPage: this.fetchPreviousPage,
2898
2910
  hasNextPage: hasNextPage(options, (_state$data = state.data) == null ? void 0 : _state$data.pages),
2899
2911
  hasPreviousPage: hasPreviousPage(options, (_state$data2 = state.data) == null ? void 0 : _state$data2.pages),
2900
- isFetchingNextPage: state.fetchStatus === 'fetching' && ((_state$fetchMeta = state.fetchMeta) == null ? void 0 : (_state$fetchMeta$fetc = _state$fetchMeta.fetchMore) == null ? void 0 : _state$fetchMeta$fetc.direction) === 'forward',
2901
- isFetchingPreviousPage: state.fetchStatus === 'fetching' && ((_state$fetchMeta2 = state.fetchMeta) == null ? void 0 : (_state$fetchMeta2$fet = _state$fetchMeta2.fetchMore) == null ? void 0 : _state$fetchMeta2$fet.direction) === 'backward'
2912
+ isFetchingNextPage,
2913
+ isFetchingPreviousPage,
2914
+ isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
2902
2915
  };
2903
2916
  }
2904
2917