@tanstack/solid-query 5.51.4 → 5.51.6
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 +5 -1
- package/build/dev.js +5 -1
- package/build/index.cjs +5 -1
- package/build/index.js +5 -1
- package/package.json +2 -2
- package/src/__tests__/createQuery.test.tsx +118 -0
- package/src/createBaseQuery.ts +5 -1
package/build/dev.cjs
CHANGED
|
@@ -143,7 +143,11 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
143
143
|
const obs = observer();
|
|
144
144
|
return obs.subscribe((result) => {
|
|
145
145
|
observerResult = result;
|
|
146
|
-
queueMicrotask(() =>
|
|
146
|
+
queueMicrotask(() => {
|
|
147
|
+
if (unsubscribe) {
|
|
148
|
+
refetch();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
147
151
|
});
|
|
148
152
|
};
|
|
149
153
|
function setStateWithReconciliation(res) {
|
package/build/dev.js
CHANGED
|
@@ -142,7 +142,11 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
142
142
|
const obs = observer();
|
|
143
143
|
return obs.subscribe((result) => {
|
|
144
144
|
observerResult = result;
|
|
145
|
-
queueMicrotask(() =>
|
|
145
|
+
queueMicrotask(() => {
|
|
146
|
+
if (unsubscribe) {
|
|
147
|
+
refetch();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
146
150
|
});
|
|
147
151
|
};
|
|
148
152
|
function setStateWithReconciliation(res) {
|
package/build/index.cjs
CHANGED
|
@@ -134,7 +134,11 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
134
134
|
const obs = observer();
|
|
135
135
|
return obs.subscribe((result) => {
|
|
136
136
|
observerResult = result;
|
|
137
|
-
queueMicrotask(() =>
|
|
137
|
+
queueMicrotask(() => {
|
|
138
|
+
if (unsubscribe) {
|
|
139
|
+
refetch();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
138
142
|
});
|
|
139
143
|
};
|
|
140
144
|
function setStateWithReconciliation(res) {
|
package/build/index.js
CHANGED
|
@@ -133,7 +133,11 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
133
133
|
const obs = observer();
|
|
134
134
|
return obs.subscribe((result) => {
|
|
135
135
|
observerResult = result;
|
|
136
|
-
queueMicrotask(() =>
|
|
136
|
+
queueMicrotask(() => {
|
|
137
|
+
if (unsubscribe) {
|
|
138
|
+
refetch();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
137
141
|
});
|
|
138
142
|
};
|
|
139
143
|
function setStateWithReconciliation(res) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "5.51.
|
|
3
|
+
"version": "5.51.6",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"src"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@tanstack/query-core": "5.51.
|
|
47
|
+
"@tanstack/query-core": "5.51.5"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"tsup-preset-solid": "^2.2.0",
|
|
@@ -3528,6 +3528,124 @@ describe('createQuery', () => {
|
|
|
3528
3528
|
])
|
|
3529
3529
|
})
|
|
3530
3530
|
|
|
3531
|
+
// See https://github.com/TanStack/query/issues/7711
|
|
3532
|
+
it('race condition: should cleanup observers after component that created the query is unmounted #1', async () => {
|
|
3533
|
+
const key = queryKey()
|
|
3534
|
+
|
|
3535
|
+
function Component() {
|
|
3536
|
+
let val = 1
|
|
3537
|
+
const dataQuery = createQuery(() => ({
|
|
3538
|
+
queryKey: [key],
|
|
3539
|
+
queryFn: () => {
|
|
3540
|
+
return val++
|
|
3541
|
+
},
|
|
3542
|
+
}))
|
|
3543
|
+
|
|
3544
|
+
return (
|
|
3545
|
+
<div>
|
|
3546
|
+
<p>component</p>
|
|
3547
|
+
<p>data: {String(dataQuery.data)}</p>
|
|
3548
|
+
</div>
|
|
3549
|
+
)
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3552
|
+
const Outer = () => {
|
|
3553
|
+
const [showComp, setShowComp] = createSignal(true)
|
|
3554
|
+
return (
|
|
3555
|
+
<div>
|
|
3556
|
+
<button
|
|
3557
|
+
onClick={() => {
|
|
3558
|
+
queryClient.invalidateQueries()
|
|
3559
|
+
setShowComp(!showComp())
|
|
3560
|
+
}}
|
|
3561
|
+
>
|
|
3562
|
+
toggle
|
|
3563
|
+
</button>
|
|
3564
|
+
{showComp() ? <Component /> : <div>not showing</div>}
|
|
3565
|
+
</div>
|
|
3566
|
+
)
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
const rendered = render(() => (
|
|
3570
|
+
<QueryClientProvider client={queryClient}>
|
|
3571
|
+
<Outer />
|
|
3572
|
+
</QueryClientProvider>
|
|
3573
|
+
))
|
|
3574
|
+
|
|
3575
|
+
await waitFor(() => rendered.getByText('component'))
|
|
3576
|
+
fireEvent.click(rendered.getByText('toggle'))
|
|
3577
|
+
await waitFor(() => rendered.getByText('not showing'))
|
|
3578
|
+
fireEvent.click(rendered.getByText('toggle'))
|
|
3579
|
+
await waitFor(() => rendered.getByText('component'))
|
|
3580
|
+
fireEvent.click(rendered.getByText('toggle'))
|
|
3581
|
+
await waitFor(() => rendered.getByText('not showing'))
|
|
3582
|
+
|
|
3583
|
+
const entry = queryClient.getQueryCache().find({
|
|
3584
|
+
queryKey: [key],
|
|
3585
|
+
})!
|
|
3586
|
+
|
|
3587
|
+
expect(entry.getObserversCount()).toBe(0)
|
|
3588
|
+
})
|
|
3589
|
+
|
|
3590
|
+
// See https://github.com/TanStack/query/issues/7711
|
|
3591
|
+
it('race condition: should cleanup observers after component that created the query is unmounted #2', async () => {
|
|
3592
|
+
const key = queryKey()
|
|
3593
|
+
|
|
3594
|
+
function Component() {
|
|
3595
|
+
let val = 1
|
|
3596
|
+
const dataQuery = createQuery(() => ({
|
|
3597
|
+
queryKey: [key],
|
|
3598
|
+
queryFn: () => {
|
|
3599
|
+
return val++
|
|
3600
|
+
},
|
|
3601
|
+
}))
|
|
3602
|
+
|
|
3603
|
+
return (
|
|
3604
|
+
<div>
|
|
3605
|
+
<p>component</p>
|
|
3606
|
+
<p>data: {String(dataQuery.data)}</p>
|
|
3607
|
+
</div>
|
|
3608
|
+
)
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3611
|
+
const Outer = () => {
|
|
3612
|
+
const [showComp, setShowComp] = createSignal(true)
|
|
3613
|
+
return (
|
|
3614
|
+
<div>
|
|
3615
|
+
<button
|
|
3616
|
+
onClick={() => {
|
|
3617
|
+
queueMicrotask(() => setShowComp(!showComp()))
|
|
3618
|
+
queryClient.invalidateQueries()
|
|
3619
|
+
}}
|
|
3620
|
+
>
|
|
3621
|
+
toggle
|
|
3622
|
+
</button>
|
|
3623
|
+
{showComp() ? <Component /> : <div>not showing</div>}
|
|
3624
|
+
</div>
|
|
3625
|
+
)
|
|
3626
|
+
}
|
|
3627
|
+
|
|
3628
|
+
const rendered = render(() => (
|
|
3629
|
+
<QueryClientProvider client={queryClient}>
|
|
3630
|
+
<Outer />
|
|
3631
|
+
</QueryClientProvider>
|
|
3632
|
+
))
|
|
3633
|
+
|
|
3634
|
+
await waitFor(() => rendered.getByText('component'))
|
|
3635
|
+
fireEvent.click(rendered.getByText('toggle'))
|
|
3636
|
+
await waitFor(() => rendered.getByText('not showing'))
|
|
3637
|
+
fireEvent.click(rendered.getByText('toggle'))
|
|
3638
|
+
await waitFor(() => rendered.getByText('component'))
|
|
3639
|
+
fireEvent.click(rendered.getByText('toggle'))
|
|
3640
|
+
await waitFor(() => rendered.getByText('not showing'))
|
|
3641
|
+
|
|
3642
|
+
const entry = queryClient.getQueryCache().find({
|
|
3643
|
+
queryKey: [key],
|
|
3644
|
+
})!
|
|
3645
|
+
|
|
3646
|
+
expect(entry.getObserversCount()).toBe(0)
|
|
3647
|
+
})
|
|
3648
|
+
|
|
3531
3649
|
it('should mark query as fetching, when using initialData', async () => {
|
|
3532
3650
|
const key = queryKey()
|
|
3533
3651
|
const results: Array<DefinedCreateQueryResult<string>> = []
|
package/src/createBaseQuery.ts
CHANGED
|
@@ -179,7 +179,11 @@ export function createBaseQuery<
|
|
|
179
179
|
const obs = observer()
|
|
180
180
|
return obs.subscribe((result) => {
|
|
181
181
|
observerResult = result
|
|
182
|
-
queueMicrotask(() =>
|
|
182
|
+
queueMicrotask(() => {
|
|
183
|
+
if (unsubscribe) {
|
|
184
|
+
refetch()
|
|
185
|
+
}
|
|
186
|
+
})
|
|
183
187
|
})
|
|
184
188
|
}
|
|
185
189
|
|