@tanstack/react-query 5.0.0-alpha.85 → 5.0.0-alpha.86

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.
@@ -11,7 +11,7 @@ export declare const Blink: ({ duration, children, }: {
11
11
  }) => JSX.Element;
12
12
  export declare function createQueryClient(config?: QueryClientConfig): QueryClient;
13
13
  export declare function mockVisibilityState(value: DocumentVisibilityState): SpyInstance<[], DocumentVisibilityState>;
14
- export declare function mockNavigatorOnLine(value: boolean): SpyInstance<[], boolean>;
14
+ export declare function mockOnlineManagerIsOnline(value: boolean): SpyInstance<[], boolean>;
15
15
  export declare function queryKey(): Array<string>;
16
16
  export declare function sleep(timeout: number): Promise<void>;
17
17
  export declare function setActTimeout(fn: () => void, ms?: number): NodeJS.Timeout;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAGpD,OAAO,EAAE,WAAW,EAAuB,MAAM,IAAI,CAAA;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAA;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAEzC,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,KAAK,CAAC,YAAY,GACrB,UAAU,CAAC,OAAO,MAAM,CAAC,CAW3B;AAED,eAAO,MAAM,KAAK;cAIN,MAAM;cACN,MAAM,SAAS;iBAa1B,CAAA;AAED,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,WAAW,CAEzE;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,uBAAuB,GAC7B,WAAW,CAAC,EAAE,EAAE,uBAAuB,CAAC,CAE1C;AAED,wBAAg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AAID,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,cAW5C;AAED,eAAO,MAAM,YAAY,UAAW,MAAM,IAAI,YAAS,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query",
3
- "version": "5.0.0-alpha.85",
3
+ "version": "5.0.0-alpha.86",
4
4
  "description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "client-only": "0.0.1",
37
- "@tanstack/query-core": "5.0.0-alpha.85"
37
+ "@tanstack/query-core": "5.0.0-alpha.86"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.2.4",
@@ -7,7 +7,7 @@ import { vi } from 'vitest'
7
7
  import { MutationCache, QueryCache, useMutation } from '..'
8
8
  import {
9
9
  createQueryClient,
10
- mockNavigatorOnLine,
10
+ mockOnlineManagerIsOnline,
11
11
  queryKey,
12
12
  renderWithClient,
13
13
  setActTimeout,
@@ -427,7 +427,7 @@ describe('useMutation', () => {
427
427
  })
428
428
 
429
429
  it('should not retry mutations while offline', async () => {
430
- const onlineMock = mockNavigatorOnLine(false)
430
+ const onlineMock = mockOnlineManagerIsOnline(false)
431
431
 
432
432
  let count = 0
433
433
 
@@ -455,6 +455,8 @@ describe('useMutation', () => {
455
455
 
456
456
  const rendered = renderWithClient(queryClient, <Page />)
457
457
 
458
+ window.dispatchEvent(new Event('offline'))
459
+
458
460
  await waitFor(() => {
459
461
  expect(
460
462
  rendered.getByText('error: null, status: idle, isPaused: false'),
@@ -471,7 +473,7 @@ describe('useMutation', () => {
471
473
 
472
474
  expect(count).toBe(0)
473
475
 
474
- onlineMock.mockReturnValue(true)
476
+ onlineMock.mockRestore()
475
477
  window.dispatchEvent(new Event('online'))
476
478
 
477
479
  await sleep(100)
@@ -483,12 +485,10 @@ describe('useMutation', () => {
483
485
  })
484
486
 
485
487
  expect(count).toBe(2)
486
-
487
- onlineMock.mockRestore()
488
488
  })
489
489
 
490
490
  it('should call onMutate even if paused', async () => {
491
- const onlineMock = mockNavigatorOnLine(false)
491
+ const onlineMock = mockOnlineManagerIsOnline(false)
492
492
  const onMutate = vi.fn()
493
493
  let count = 0
494
494
 
@@ -517,6 +517,8 @@ describe('useMutation', () => {
517
517
 
518
518
  await rendered.findByText('data: null, status: idle, isPaused: false')
519
519
 
520
+ window.dispatchEvent(new Event('offline'))
521
+
520
522
  fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
521
523
 
522
524
  await rendered.findByText('data: null, status: pending, isPaused: true')
@@ -524,19 +526,17 @@ describe('useMutation', () => {
524
526
  expect(onMutate).toHaveBeenCalledTimes(1)
525
527
  expect(onMutate).toHaveBeenCalledWith('todo')
526
528
 
527
- onlineMock.mockReturnValue(true)
529
+ onlineMock.mockRestore()
528
530
  window.dispatchEvent(new Event('online'))
529
531
 
530
532
  await rendered.findByText('data: 1, status: success, isPaused: false')
531
533
 
532
534
  expect(onMutate).toHaveBeenCalledTimes(1)
533
535
  expect(count).toBe(1)
534
-
535
- onlineMock.mockRestore()
536
536
  })
537
537
 
538
538
  it('should optimistically go to paused state if offline', async () => {
539
- const onlineMock = mockNavigatorOnLine(false)
539
+ const onlineMock = mockOnlineManagerIsOnline(false)
540
540
  let count = 0
541
541
  const states: Array<string> = []
542
542
 
@@ -566,6 +566,8 @@ describe('useMutation', () => {
566
566
 
567
567
  await rendered.findByText('data: null, status: idle, isPaused: false')
568
568
 
569
+ window.dispatchEvent(new Event('offline'))
570
+
569
571
  fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
570
572
 
571
573
  await rendered.findByText('data: null, status: pending, isPaused: true')
@@ -574,16 +576,14 @@ describe('useMutation', () => {
574
576
  expect(states[0]).toBe('idle, false')
575
577
  expect(states[1]).toBe('pending, true')
576
578
 
577
- onlineMock.mockReturnValue(true)
579
+ onlineMock.mockRestore()
578
580
  window.dispatchEvent(new Event('online'))
579
581
 
580
582
  await rendered.findByText('data: 1, status: success, isPaused: false')
581
-
582
- onlineMock.mockRestore()
583
583
  })
584
584
 
585
585
  it('should be able to retry a mutation when online', async () => {
586
- const onlineMock = mockNavigatorOnLine(false)
586
+ const onlineMock = mockOnlineManagerIsOnline(false)
587
587
 
588
588
  let count = 0
589
589
  const states: UseMutationResult<any, any, any, any>[] = []
@@ -608,6 +608,7 @@ describe('useMutation', () => {
608
608
 
609
609
  React.useEffect(() => {
610
610
  setActTimeout(() => {
611
+ window.dispatchEvent(new Event('offline'))
611
612
  mutate('todo')
612
613
  }, 10)
613
614
  }, [mutate])
@@ -645,7 +646,7 @@ describe('useMutation', () => {
645
646
  failureReason: new Error('oops'),
646
647
  })
647
648
 
648
- onlineMock.mockReturnValue(true)
649
+ onlineMock.mockRestore()
649
650
  window.dispatchEvent(new Event('online'))
650
651
 
651
652
  await sleep(50)
@@ -664,8 +665,6 @@ describe('useMutation', () => {
664
665
  failureReason: null,
665
666
  data: 'data',
666
667
  })
667
-
668
- onlineMock.mockRestore()
669
668
  })
670
669
 
671
670
  it('should not change state if unmounted', async () => {
@@ -8,7 +8,7 @@ import {
8
8
  Blink,
9
9
  createQueryClient,
10
10
  expectType,
11
- mockNavigatorOnLine,
11
+ mockOnlineManagerIsOnline,
12
12
  mockVisibilityState,
13
13
  queryKey,
14
14
  renderWithClient,
@@ -18,7 +18,6 @@ import {
18
18
  import type {
19
19
  DefinedUseQueryResult,
20
20
  QueryFunction,
21
- QueryFunctionContext,
22
21
  UseQueryOptions,
23
22
  UseQueryResult,
24
23
  } from '..'
@@ -2437,33 +2436,6 @@ describe('useQuery', () => {
2437
2436
  rendered.getByText('status: pending')
2438
2437
  })
2439
2438
 
2440
- // See https://github.com/tannerlinsley/react-query/issues/147
2441
- it('should not pass stringified variables to query function', async () => {
2442
- const key = queryKey()
2443
- const variables = { number: 5, boolean: false, object: {}, array: [] }
2444
- type CustomQueryKey = [typeof key, typeof variables]
2445
- const states: UseQueryResult<CustomQueryKey>[] = []
2446
-
2447
- const queryFn = async (ctx: QueryFunctionContext<CustomQueryKey>) => {
2448
- await sleep(10)
2449
- return ctx.queryKey
2450
- }
2451
-
2452
- function Page() {
2453
- const state = useQuery({ queryKey: [key, variables], queryFn })
2454
- states.push(state)
2455
- return <div>{state.status}</div>
2456
- }
2457
-
2458
- const rendered = renderWithClient(queryClient, <Page />)
2459
-
2460
- await waitFor(() => {
2461
- rendered.getByText('success')
2462
- })
2463
-
2464
- expect(states[1]?.data).toEqual([key, variables])
2465
- })
2466
-
2467
2439
  it('should not refetch query on focus when `enabled` is set to `false`', async () => {
2468
2440
  const key = queryKey()
2469
2441
  const queryFn = vi.fn<unknown[], string>().mockReturnValue('data')
@@ -5081,7 +5053,7 @@ describe('useQuery', () => {
5081
5053
 
5082
5054
  describe('networkMode online', () => {
5083
5055
  it('online queries should not start fetching if you are offline', async () => {
5084
- const onlineMock = mockNavigatorOnLine(false)
5056
+ const onlineMock = mockOnlineManagerIsOnline(false)
5085
5057
 
5086
5058
  const key = queryKey()
5087
5059
  const states: Array<any> = []
@@ -5110,10 +5082,11 @@ describe('useQuery', () => {
5110
5082
  }
5111
5083
 
5112
5084
  const rendered = renderWithClient(queryClient, <Page />)
5085
+ window.dispatchEvent(new Event('offline'))
5113
5086
 
5114
5087
  await waitFor(() => rendered.getByText('status: pending, isPaused: true'))
5115
5088
 
5116
- onlineMock.mockReturnValue(true)
5089
+ onlineMock.mockRestore()
5117
5090
  window.dispatchEvent(new Event('online'))
5118
5091
 
5119
5092
  await waitFor(() =>
@@ -5124,8 +5097,6 @@ describe('useQuery', () => {
5124
5097
  })
5125
5098
 
5126
5099
  expect(states).toEqual(['paused', 'fetching', 'idle'])
5127
-
5128
- onlineMock.mockRestore()
5129
5100
  })
5130
5101
 
5131
5102
  it('online queries should not refetch if you are offline', async () => {
@@ -5163,7 +5134,9 @@ describe('useQuery', () => {
5163
5134
 
5164
5135
  await waitFor(() => rendered.getByText('data: data1'))
5165
5136
 
5166
- const onlineMock = mockNavigatorOnLine(false)
5137
+ const onlineMock = mockOnlineManagerIsOnline(false)
5138
+ window.dispatchEvent(new Event('offline'))
5139
+
5167
5140
  fireEvent.click(rendered.getByRole('button', { name: /invalidate/i }))
5168
5141
 
5169
5142
  await waitFor(() =>
@@ -5173,7 +5146,7 @@ describe('useQuery', () => {
5173
5146
  )
5174
5147
  await waitFor(() => rendered.getByText('failureReason: null'))
5175
5148
 
5176
- onlineMock.mockReturnValue(true)
5149
+ onlineMock.mockRestore()
5177
5150
  window.dispatchEvent(new Event('online'))
5178
5151
 
5179
5152
  await waitFor(() =>
@@ -5192,8 +5165,6 @@ describe('useQuery', () => {
5192
5165
  await waitFor(() => {
5193
5166
  expect(rendered.getByText('data: data2')).toBeInTheDocument()
5194
5167
  })
5195
-
5196
- onlineMock.mockRestore()
5197
5168
  })
5198
5169
 
5199
5170
  it('online queries should not refetch if you are offline and refocus', async () => {
@@ -5229,7 +5200,7 @@ describe('useQuery', () => {
5229
5200
 
5230
5201
  await waitFor(() => rendered.getByText('data: data1'))
5231
5202
 
5232
- const onlineMock = mockNavigatorOnLine(false)
5203
+ const onlineMock = mockOnlineManagerIsOnline(false)
5233
5204
  fireEvent.click(rendered.getByRole('button', { name: /invalidate/i }))
5234
5205
 
5235
5206
  await waitFor(() =>
@@ -5275,7 +5246,7 @@ describe('useQuery', () => {
5275
5246
  )
5276
5247
  }
5277
5248
 
5278
- const onlineMock = mockNavigatorOnLine(false)
5249
+ const onlineMock = mockOnlineManagerIsOnline(false)
5279
5250
 
5280
5251
  const rendered = renderWithClient(queryClient, <Page />)
5281
5252
 
@@ -5326,7 +5297,7 @@ describe('useQuery', () => {
5326
5297
  )
5327
5298
  }
5328
5299
 
5329
- const onlineMock = mockNavigatorOnLine(false)
5300
+ const onlineMock = mockOnlineManagerIsOnline(false)
5330
5301
 
5331
5302
  const rendered = renderWithClient(queryClient, <Page />)
5332
5303
 
@@ -5380,9 +5351,10 @@ describe('useQuery', () => {
5380
5351
  )
5381
5352
  }
5382
5353
 
5383
- const onlineMock = mockNavigatorOnLine(false)
5354
+ const onlineMock = mockOnlineManagerIsOnline(false)
5384
5355
 
5385
5356
  const rendered = renderWithClient(queryClient, <Page />)
5357
+ window.dispatchEvent(new Event('offline'))
5386
5358
 
5387
5359
  await waitFor(() =>
5388
5360
  rendered.getByText('status: success, fetchStatus: paused'),
@@ -5405,7 +5377,7 @@ describe('useQuery', () => {
5405
5377
  window.dispatchEvent(new Event('visibilitychange'))
5406
5378
  })
5407
5379
 
5408
- onlineMock.mockReturnValue(true)
5380
+ onlineMock.mockRestore()
5409
5381
  act(() => {
5410
5382
  window.dispatchEvent(new Event('online'))
5411
5383
  })
@@ -5418,7 +5390,6 @@ describe('useQuery', () => {
5418
5390
  })
5419
5391
 
5420
5392
  expect(count).toBe(1)
5421
- onlineMock.mockRestore()
5422
5393
  })
5423
5394
 
5424
5395
  it('online queries should pause retries if you are offline', async () => {
@@ -5457,7 +5428,7 @@ describe('useQuery', () => {
5457
5428
  )
5458
5429
  await waitFor(() => rendered.getByText('failureReason: failed1'))
5459
5430
 
5460
- const onlineMock = mockNavigatorOnLine(false)
5431
+ const onlineMock = mockOnlineManagerIsOnline(false)
5461
5432
  window.dispatchEvent(new Event('offline'))
5462
5433
 
5463
5434
  await sleep(20)
@@ -5519,17 +5490,19 @@ describe('useQuery', () => {
5519
5490
  )
5520
5491
  }
5521
5492
 
5522
- const onlineMock = mockNavigatorOnLine(false)
5493
+ const onlineMock = mockOnlineManagerIsOnline(false)
5523
5494
 
5524
5495
  const rendered = renderWithClient(queryClient, <Page />)
5525
5496
 
5497
+ window.dispatchEvent(new Event('offline'))
5498
+
5526
5499
  await waitFor(() =>
5527
5500
  rendered.getByText('status: pending, fetchStatus: paused'),
5528
5501
  )
5529
5502
 
5530
5503
  fireEvent.click(rendered.getByRole('button', { name: /hide/i }))
5531
5504
 
5532
- onlineMock.mockReturnValue(true)
5505
+ onlineMock.mockRestore()
5533
5506
  window.dispatchEvent(new Event('online'))
5534
5507
 
5535
5508
  await waitFor(() => {
@@ -5542,8 +5515,6 @@ describe('useQuery', () => {
5542
5515
  // give it a bit more time to make sure queryFn is not called again
5543
5516
  await sleep(15)
5544
5517
  expect(count).toBe(1)
5545
-
5546
- onlineMock.mockRestore()
5547
5518
  })
5548
5519
 
5549
5520
  it('online queries should not fetch if paused and we go online when cancelled and no refetchOnReconnect', async () => {
@@ -5576,7 +5547,7 @@ describe('useQuery', () => {
5576
5547
  )
5577
5548
  }
5578
5549
 
5579
- const onlineMock = mockNavigatorOnLine(false)
5550
+ const onlineMock = mockOnlineManagerIsOnline(false)
5580
5551
 
5581
5552
  const rendered = renderWithClient(queryClient, <Page />)
5582
5553
 
@@ -5652,7 +5623,7 @@ describe('useQuery', () => {
5652
5623
  rendered.getByText('status: success, fetchStatus: idle'),
5653
5624
  )
5654
5625
 
5655
- const onlineMock = mockNavigatorOnLine(false)
5626
+ const onlineMock = mockOnlineManagerIsOnline(false)
5656
5627
 
5657
5628
  fireEvent.click(rendered.getByRole('button', { name: /invalidate/i }))
5658
5629
 
@@ -5682,7 +5653,7 @@ describe('useQuery', () => {
5682
5653
 
5683
5654
  describe('networkMode always', () => {
5684
5655
  it('always queries should start fetching even if you are offline', async () => {
5685
- const onlineMock = mockNavigatorOnLine(false)
5656
+ const onlineMock = mockOnlineManagerIsOnline(false)
5686
5657
 
5687
5658
  const key = queryKey()
5688
5659
  let count = 0
@@ -5722,7 +5693,7 @@ describe('useQuery', () => {
5722
5693
  })
5723
5694
 
5724
5695
  it('always queries should not pause retries', async () => {
5725
- const onlineMock = mockNavigatorOnLine(false)
5696
+ const onlineMock = mockOnlineManagerIsOnline(false)
5726
5697
 
5727
5698
  const key = queryKey()
5728
5699
  let count = 0
@@ -5768,7 +5739,7 @@ describe('useQuery', () => {
5768
5739
 
5769
5740
  describe('networkMode offlineFirst', () => {
5770
5741
  it('offlineFirst queries should start fetching if you are offline, but pause retries', async () => {
5771
- const onlineMock = mockNavigatorOnLine(false)
5742
+ const onlineMock = mockOnlineManagerIsOnline(false)
5772
5743
 
5773
5744
  const key = queryKey()
5774
5745
  let count = 0
@@ -5799,6 +5770,8 @@ describe('useQuery', () => {
5799
5770
 
5800
5771
  const rendered = renderWithClient(queryClient, <Page />)
5801
5772
 
5773
+ window.dispatchEvent(new Event('offline'))
5774
+
5802
5775
  await waitFor(() =>
5803
5776
  rendered.getByText(
5804
5777
  'status: pending, fetchStatus: paused, failureCount: 1',
@@ -5808,7 +5781,7 @@ describe('useQuery', () => {
5808
5781
 
5809
5782
  expect(count).toBe(1)
5810
5783
 
5811
- onlineMock.mockReturnValue(true)
5784
+ onlineMock.mockRestore()
5812
5785
  window.dispatchEvent(new Event('online'))
5813
5786
 
5814
5787
  await waitFor(() =>
@@ -5817,8 +5790,6 @@ describe('useQuery', () => {
5817
5790
  await waitFor(() => rendered.getByText('failureReason: failed3'))
5818
5791
 
5819
5792
  expect(count).toBe(3)
5820
-
5821
- onlineMock.mockRestore()
5822
5793
  })
5823
5794
  })
5824
5795
 
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react'
2
2
  import { act, render } from '@testing-library/react'
3
+
3
4
  import * as utils from '@tanstack/query-core'
4
5
  import { vi } from 'vitest'
5
- import { QueryClient, QueryClientProvider } from '..'
6
+ import { QueryClient, QueryClientProvider, onlineManager } from '..'
6
7
  import type { QueryClientConfig } from '..'
7
8
  import type { SpyInstance } from 'vitest'
8
9
 
@@ -52,8 +53,10 @@ export function mockVisibilityState(
52
53
  return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
53
54
  }
54
55
 
55
- export function mockNavigatorOnLine(value: boolean): SpyInstance<[], boolean> {
56
- return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
56
+ export function mockOnlineManagerIsOnline(
57
+ value: boolean,
58
+ ): SpyInstance<[], boolean> {
59
+ return vi.spyOn(onlineManager, 'isOnline').mockReturnValue(value)
57
60
  }
58
61
 
59
62
  let queryKeyCount = 0