@tanstack/query-core 4.24.3 → 4.24.4
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/lib/mutationCache.d.ts +0 -1
- package/build/lib/mutationCache.esm.js +2 -8
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js +2 -8
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs +2 -8
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/umd/index.development.js +2 -8
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/mutationCache.ts +8 -17
- package/src/tests/queryClient.test.tsx +1 -79
package/package.json
CHANGED
package/src/mutationCache.ts
CHANGED
|
@@ -79,7 +79,6 @@ export class MutationCache extends Subscribable<MutationCacheListener> {
|
|
|
79
79
|
|
|
80
80
|
private mutations: Mutation<any, any, any, any>[]
|
|
81
81
|
private mutationId: number
|
|
82
|
-
private resuming: Promise<void> | undefined
|
|
83
82
|
|
|
84
83
|
constructor(config?: MutationCacheConfig) {
|
|
85
84
|
super()
|
|
@@ -154,21 +153,13 @@ export class MutationCache extends Subscribable<MutationCacheListener> {
|
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
resumePausedMutations(): Promise<void> {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
),
|
|
166
|
-
)
|
|
167
|
-
.then(() => {
|
|
168
|
-
this.resuming = undefined
|
|
169
|
-
})
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return this.resuming
|
|
156
|
+
const pausedMutations = this.mutations.filter((x) => x.state.isPaused)
|
|
157
|
+
return notifyManager.batch(() =>
|
|
158
|
+
pausedMutations.reduce(
|
|
159
|
+
(promise, mutation) =>
|
|
160
|
+
promise.then(() => mutation.continue().catch(noop)),
|
|
161
|
+
Promise.resolve(),
|
|
162
|
+
),
|
|
163
|
+
)
|
|
173
164
|
}
|
|
174
165
|
}
|
|
@@ -8,9 +8,8 @@ import type {
|
|
|
8
8
|
QueryFunction,
|
|
9
9
|
QueryObserverOptions,
|
|
10
10
|
} from '..'
|
|
11
|
-
import { InfiniteQueryObserver,
|
|
11
|
+
import { InfiniteQueryObserver, QueryObserver } from '..'
|
|
12
12
|
import { focusManager, onlineManager } from '..'
|
|
13
|
-
import { noop } from '../utils'
|
|
14
13
|
|
|
15
14
|
describe('queryClient', () => {
|
|
16
15
|
let queryClient: QueryClient
|
|
@@ -1469,83 +1468,6 @@ describe('queryClient', () => {
|
|
|
1469
1468
|
onlineManager.setOnline(undefined)
|
|
1470
1469
|
})
|
|
1471
1470
|
|
|
1472
|
-
test('should resume paused mutations when coming online', async () => {
|
|
1473
|
-
const consoleMock = jest.spyOn(console, 'error')
|
|
1474
|
-
consoleMock.mockImplementation(() => undefined)
|
|
1475
|
-
onlineManager.setOnline(false)
|
|
1476
|
-
|
|
1477
|
-
const observer1 = new MutationObserver(queryClient, {
|
|
1478
|
-
mutationFn: async () => 1,
|
|
1479
|
-
})
|
|
1480
|
-
|
|
1481
|
-
const observer2 = new MutationObserver(queryClient, {
|
|
1482
|
-
mutationFn: async () => 2,
|
|
1483
|
-
})
|
|
1484
|
-
void observer1.mutate().catch(noop)
|
|
1485
|
-
void observer2.mutate().catch(noop)
|
|
1486
|
-
|
|
1487
|
-
await waitFor(() => {
|
|
1488
|
-
expect(observer1.getCurrentResult().isPaused).toBeTruthy()
|
|
1489
|
-
expect(observer2.getCurrentResult().isPaused).toBeTruthy()
|
|
1490
|
-
})
|
|
1491
|
-
|
|
1492
|
-
onlineManager.setOnline(true)
|
|
1493
|
-
|
|
1494
|
-
await waitFor(() => {
|
|
1495
|
-
expect(observer1.getCurrentResult().status).toBe('success')
|
|
1496
|
-
expect(observer1.getCurrentResult().status).toBe('success')
|
|
1497
|
-
})
|
|
1498
|
-
|
|
1499
|
-
onlineManager.setOnline(undefined)
|
|
1500
|
-
})
|
|
1501
|
-
|
|
1502
|
-
test('should resume paused mutations one after the other when invoked manually at the same time', async () => {
|
|
1503
|
-
const consoleMock = jest.spyOn(console, 'error')
|
|
1504
|
-
consoleMock.mockImplementation(() => undefined)
|
|
1505
|
-
onlineManager.setOnline(false)
|
|
1506
|
-
|
|
1507
|
-
const orders: Array<string> = []
|
|
1508
|
-
|
|
1509
|
-
const observer1 = new MutationObserver(queryClient, {
|
|
1510
|
-
mutationFn: async () => {
|
|
1511
|
-
orders.push('1start')
|
|
1512
|
-
await sleep(50)
|
|
1513
|
-
orders.push('1end')
|
|
1514
|
-
return 1
|
|
1515
|
-
},
|
|
1516
|
-
})
|
|
1517
|
-
|
|
1518
|
-
const observer2 = new MutationObserver(queryClient, {
|
|
1519
|
-
mutationFn: async () => {
|
|
1520
|
-
orders.push('2start')
|
|
1521
|
-
await sleep(20)
|
|
1522
|
-
orders.push('2end')
|
|
1523
|
-
return 2
|
|
1524
|
-
},
|
|
1525
|
-
})
|
|
1526
|
-
void observer1.mutate().catch(noop)
|
|
1527
|
-
void observer2.mutate().catch(noop)
|
|
1528
|
-
|
|
1529
|
-
await waitFor(() => {
|
|
1530
|
-
expect(observer1.getCurrentResult().isPaused).toBeTruthy()
|
|
1531
|
-
expect(observer2.getCurrentResult().isPaused).toBeTruthy()
|
|
1532
|
-
})
|
|
1533
|
-
|
|
1534
|
-
onlineManager.setOnline(undefined)
|
|
1535
|
-
void queryClient.resumePausedMutations()
|
|
1536
|
-
await sleep(5)
|
|
1537
|
-
await queryClient.resumePausedMutations()
|
|
1538
|
-
|
|
1539
|
-
await waitFor(() => {
|
|
1540
|
-
expect(observer1.getCurrentResult().status).toBe('success')
|
|
1541
|
-
expect(observer2.getCurrentResult().status).toBe('success')
|
|
1542
|
-
})
|
|
1543
|
-
|
|
1544
|
-
console.log('orders', orders)
|
|
1545
|
-
|
|
1546
|
-
expect(orders).toEqual(['1start', '1end', '2start', '2end'])
|
|
1547
|
-
})
|
|
1548
|
-
|
|
1549
1471
|
test('should notify queryCache and mutationCache after multiple mounts and single unmount', async () => {
|
|
1550
1472
|
const testClient = createQueryClient()
|
|
1551
1473
|
testClient.mount()
|