@tanstack/solid-query 4.11.0 → 4.12.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.
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/lib/__tests__/createInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/createMutation.test.d.ts +1 -0
- package/build/lib/__tests__/createQueries.test.d.ts +1 -0
- package/build/lib/__tests__/createQuery.test.d.ts +1 -0
- package/build/lib/__tests__/createQuery.types.test.d.ts +2 -0
- package/build/lib/__tests__/suspense.test.d.ts +1 -0
- package/build/lib/__tests__/transition.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsMutating.test.d.ts +1 -0
- package/build/lib/__tests__/utils.d.ts +27 -0
- package/build/lib/createBaseQuery.esm.js +18 -2
- package/build/lib/createBaseQuery.esm.js.map +1 -1
- package/build/lib/createBaseQuery.js +18 -2
- package/build/lib/createBaseQuery.js.map +1 -1
- package/build/lib/createBaseQuery.mjs +18 -2
- package/build/lib/createBaseQuery.mjs.map +1 -1
- package/build/solid/__tests__/QueryClientProvider.test.jsx +185 -0
- package/build/solid/__tests__/createInfiniteQuery.test.jsx +1440 -0
- package/build/solid/__tests__/createMutation.test.jsx +810 -0
- package/build/solid/__tests__/createQueries.test.jsx +958 -0
- package/build/solid/__tests__/createQuery.test.jsx +4553 -0
- package/build/solid/__tests__/createQuery.types.test.jsx +124 -0
- package/build/solid/__tests__/suspense.test.jsx +691 -0
- package/build/solid/__tests__/transition.test.jsx +39 -0
- package/build/solid/__tests__/useIsFetching.test.jsx +209 -0
- package/build/solid/__tests__/useIsMutating.test.jsx +216 -0
- package/build/solid/__tests__/utils.jsx +55 -0
- package/build/solid/createBaseQuery.js +14 -2
- package/build/umd/index.development.js +21 -5
- 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 +5 -6
- package/src/__tests__/createQuery.test.tsx +15 -84
- package/src/__tests__/suspense.test.tsx +0 -46
- package/src/createBaseQuery.ts +14 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.0",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,11 +33,10 @@
|
|
|
33
33
|
"src"
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"jscodeshift": "^0.13.1"
|
|
36
|
+
"solid-jest": "^0.2.0"
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
|
-
"@tanstack/query-core": "4.
|
|
39
|
+
"@tanstack/query-core": "4.12.0"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
43
42
|
"solid-js": "^1.5.7"
|
|
@@ -46,7 +45,7 @@
|
|
|
46
45
|
"scripts": {
|
|
47
46
|
"clean": "rm -rf ./build",
|
|
48
47
|
"test:eslint": "../../node_modules/.bin/eslint --ext .ts,.tsx ./src",
|
|
49
|
-
"test:jest": "../../node_modules/.bin/jest --config jest.config.
|
|
50
|
-
"test:
|
|
48
|
+
"test:jest": "../../node_modules/.bin/jest --config ./jest.config.ts",
|
|
49
|
+
"test:dev": "pnpm run test:jest --watch"
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -1386,7 +1386,7 @@ describe('createQuery', () => {
|
|
|
1386
1386
|
|
|
1387
1387
|
it('should create a new query when refetching a removed query', async () => {
|
|
1388
1388
|
const key = queryKey()
|
|
1389
|
-
const states:
|
|
1389
|
+
const states: CreateQueryResult<number>[] = []
|
|
1390
1390
|
let count = 0
|
|
1391
1391
|
|
|
1392
1392
|
function Page() {
|
|
@@ -1400,7 +1400,7 @@ describe('createQuery', () => {
|
|
|
1400
1400
|
)
|
|
1401
1401
|
|
|
1402
1402
|
createRenderEffect(() => {
|
|
1403
|
-
states.push({
|
|
1403
|
+
states.push({ ...state })
|
|
1404
1404
|
})
|
|
1405
1405
|
|
|
1406
1406
|
return (
|
|
@@ -1510,7 +1510,7 @@ describe('createQuery', () => {
|
|
|
1510
1510
|
|
|
1511
1511
|
it('should use query function from hook when the existing query does not have a query function', async () => {
|
|
1512
1512
|
const key = queryKey()
|
|
1513
|
-
const results:
|
|
1513
|
+
const results: CreateQueryResult<string>[] = []
|
|
1514
1514
|
|
|
1515
1515
|
queryClient.setQueryData(key(), 'set')
|
|
1516
1516
|
|
|
@@ -1528,7 +1528,7 @@ describe('createQuery', () => {
|
|
|
1528
1528
|
)
|
|
1529
1529
|
|
|
1530
1530
|
createRenderEffect(() => {
|
|
1531
|
-
results.push({
|
|
1531
|
+
results.push({ ...result })
|
|
1532
1532
|
})
|
|
1533
1533
|
|
|
1534
1534
|
return (
|
|
@@ -1725,7 +1725,7 @@ describe('createQuery', () => {
|
|
|
1725
1725
|
|
|
1726
1726
|
it('should not fetch when switching to a disabled query', async () => {
|
|
1727
1727
|
const key = queryKey()
|
|
1728
|
-
const states:
|
|
1728
|
+
const states: CreateQueryResult<number>[] = []
|
|
1729
1729
|
|
|
1730
1730
|
function Page() {
|
|
1731
1731
|
const [count, setCount] = createSignal(0)
|
|
@@ -1744,12 +1744,7 @@ describe('createQuery', () => {
|
|
|
1744
1744
|
)
|
|
1745
1745
|
|
|
1746
1746
|
createRenderEffect(() => {
|
|
1747
|
-
|
|
1748
|
-
states.push({
|
|
1749
|
-
data,
|
|
1750
|
-
isFetching,
|
|
1751
|
-
isSuccess,
|
|
1752
|
-
})
|
|
1747
|
+
states.push({ ...state })
|
|
1753
1748
|
})
|
|
1754
1749
|
|
|
1755
1750
|
createEffect(() => {
|
|
@@ -1793,7 +1788,7 @@ describe('createQuery', () => {
|
|
|
1793
1788
|
|
|
1794
1789
|
it('should keep the previous data when keepPreviousData is set', async () => {
|
|
1795
1790
|
const key = queryKey()
|
|
1796
|
-
const states:
|
|
1791
|
+
const states: CreateQueryResult<number>[] = []
|
|
1797
1792
|
|
|
1798
1793
|
function Page() {
|
|
1799
1794
|
const [count, setCount] = createSignal(0)
|
|
@@ -1808,13 +1803,7 @@ describe('createQuery', () => {
|
|
|
1808
1803
|
)
|
|
1809
1804
|
|
|
1810
1805
|
createRenderEffect(() => {
|
|
1811
|
-
|
|
1812
|
-
states.push({
|
|
1813
|
-
data,
|
|
1814
|
-
isFetching,
|
|
1815
|
-
isSuccess,
|
|
1816
|
-
isPreviousData,
|
|
1817
|
-
})
|
|
1806
|
+
states.push({ ...state })
|
|
1818
1807
|
})
|
|
1819
1808
|
|
|
1820
1809
|
createEffect(() => {
|
|
@@ -2137,7 +2126,7 @@ describe('createQuery', () => {
|
|
|
2137
2126
|
|
|
2138
2127
|
it('should keep the previous data on disabled query when keepPreviousData is set and switching query key multiple times', async () => {
|
|
2139
2128
|
const key = queryKey()
|
|
2140
|
-
const states:
|
|
2129
|
+
const states: CreateQueryResult<number>[] = []
|
|
2141
2130
|
|
|
2142
2131
|
queryClient.setQueryData([key(), 10], 10)
|
|
2143
2132
|
|
|
@@ -2156,8 +2145,7 @@ describe('createQuery', () => {
|
|
|
2156
2145
|
)
|
|
2157
2146
|
|
|
2158
2147
|
createRenderEffect(() => {
|
|
2159
|
-
|
|
2160
|
-
states.push({ data, isFetching, isSuccess, isPreviousData })
|
|
2148
|
+
states.push({ ...state })
|
|
2161
2149
|
})
|
|
2162
2150
|
|
|
2163
2151
|
createEffect(() => {
|
|
@@ -2574,48 +2562,6 @@ describe('createQuery', () => {
|
|
|
2574
2562
|
expect(queryCache.find(key())!.options.queryFn).toBe(queryFn1)
|
|
2575
2563
|
})
|
|
2576
2564
|
|
|
2577
|
-
// TODO(lukemurray): this seems like a react implementation detail
|
|
2578
|
-
it.skip('should render correct states even in case of useEffect triggering delays', async () => {
|
|
2579
|
-
const key = queryKey()
|
|
2580
|
-
const states: CreateQueryResult<string>[] = []
|
|
2581
|
-
|
|
2582
|
-
// @ts-expect-error - we skip this test
|
|
2583
|
-
const originalUseEffect = NotReact.useEffect
|
|
2584
|
-
|
|
2585
|
-
// Try to simulate useEffect timing delay
|
|
2586
|
-
// @ts-ignore
|
|
2587
|
-
NotReact.useEffect = (...args: any[]) => {
|
|
2588
|
-
originalUseEffect(() => {
|
|
2589
|
-
setTimeout(() => {
|
|
2590
|
-
args[0]()
|
|
2591
|
-
}, 10)
|
|
2592
|
-
}, args[1])
|
|
2593
|
-
}
|
|
2594
|
-
|
|
2595
|
-
function Page() {
|
|
2596
|
-
const state = createQuery(key, () => 'data', { staleTime: Infinity })
|
|
2597
|
-
createRenderEffect(() => {
|
|
2598
|
-
states.push({ ...state })
|
|
2599
|
-
})
|
|
2600
|
-
return null
|
|
2601
|
-
}
|
|
2602
|
-
|
|
2603
|
-
render(() => (
|
|
2604
|
-
<QueryClientProvider client={queryClient}>
|
|
2605
|
-
<Page />
|
|
2606
|
-
</QueryClientProvider>
|
|
2607
|
-
))
|
|
2608
|
-
queryClient.setQueryData(key(), 'data')
|
|
2609
|
-
await sleep(50)
|
|
2610
|
-
|
|
2611
|
-
// @ts-ignore
|
|
2612
|
-
NotReact.useEffect = originalUseEffect
|
|
2613
|
-
|
|
2614
|
-
expect(states.length).toBe(2)
|
|
2615
|
-
expect(states[0]).toMatchObject({ status: 'loading' })
|
|
2616
|
-
expect(states[1]).toMatchObject({ status: 'success' })
|
|
2617
|
-
})
|
|
2618
|
-
|
|
2619
2565
|
it('should batch re-renders', async () => {
|
|
2620
2566
|
const key = queryKey()
|
|
2621
2567
|
|
|
@@ -2780,7 +2726,7 @@ describe('createQuery', () => {
|
|
|
2780
2726
|
const key = queryKey()
|
|
2781
2727
|
const variables = { number: 5, boolean: false, object: {}, array: [] }
|
|
2782
2728
|
type CustomQueryKey = readonly [ReturnType<typeof key>, typeof variables]
|
|
2783
|
-
const states:
|
|
2729
|
+
const states: CreateQueryResult<CustomQueryKey>[] = []
|
|
2784
2730
|
|
|
2785
2731
|
// TODO(lukemurray): extract the query function to a variable queryFn
|
|
2786
2732
|
|
|
@@ -5087,7 +5033,7 @@ describe('createQuery', () => {
|
|
|
5087
5033
|
|
|
5088
5034
|
it('should update query state and refetch when reset with resetQueries', async () => {
|
|
5089
5035
|
const key = queryKey()
|
|
5090
|
-
const states:
|
|
5036
|
+
const states: CreateQueryResult<number>[] = []
|
|
5091
5037
|
let count = 0
|
|
5092
5038
|
|
|
5093
5039
|
function Page() {
|
|
@@ -5102,15 +5048,7 @@ describe('createQuery', () => {
|
|
|
5102
5048
|
)
|
|
5103
5049
|
|
|
5104
5050
|
createRenderEffect(() => {
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
states.push({
|
|
5108
|
-
data,
|
|
5109
|
-
isLoading,
|
|
5110
|
-
isFetching,
|
|
5111
|
-
isSuccess,
|
|
5112
|
-
isStale,
|
|
5113
|
-
})
|
|
5051
|
+
states.push({ ...state })
|
|
5114
5052
|
})
|
|
5115
5053
|
|
|
5116
5054
|
return (
|
|
@@ -5169,7 +5107,7 @@ describe('createQuery', () => {
|
|
|
5169
5107
|
|
|
5170
5108
|
it('should update query state and not refetch when resetting a disabled query with resetQueries', async () => {
|
|
5171
5109
|
const key = queryKey()
|
|
5172
|
-
const states:
|
|
5110
|
+
const states: CreateQueryResult<number>[] = []
|
|
5173
5111
|
let count = 0
|
|
5174
5112
|
|
|
5175
5113
|
function Page() {
|
|
@@ -5184,14 +5122,7 @@ describe('createQuery', () => {
|
|
|
5184
5122
|
)
|
|
5185
5123
|
|
|
5186
5124
|
createRenderEffect(() => {
|
|
5187
|
-
|
|
5188
|
-
states.push({
|
|
5189
|
-
data,
|
|
5190
|
-
isLoading,
|
|
5191
|
-
isFetching,
|
|
5192
|
-
isSuccess,
|
|
5193
|
-
isStale,
|
|
5194
|
-
})
|
|
5125
|
+
states.push({ ...state })
|
|
5195
5126
|
})
|
|
5196
5127
|
|
|
5197
5128
|
const { refetch } = state
|
|
@@ -805,52 +805,6 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
805
805
|
expect(queryFn).toHaveBeenCalledTimes(1)
|
|
806
806
|
})
|
|
807
807
|
|
|
808
|
-
it('should not render suspense fallback when not enabled', async () => {
|
|
809
|
-
const key = queryKey()
|
|
810
|
-
|
|
811
|
-
function Page() {
|
|
812
|
-
const [enabled, setEnabled] = createSignal(false)
|
|
813
|
-
const result = createQuery(
|
|
814
|
-
key,
|
|
815
|
-
() => {
|
|
816
|
-
sleep(10)
|
|
817
|
-
return 'data'
|
|
818
|
-
},
|
|
819
|
-
{
|
|
820
|
-
suspense: true,
|
|
821
|
-
get enabled() {
|
|
822
|
-
return enabled()
|
|
823
|
-
},
|
|
824
|
-
},
|
|
825
|
-
)
|
|
826
|
-
|
|
827
|
-
return (
|
|
828
|
-
<div>
|
|
829
|
-
<button onClick={() => setEnabled(true)}>fire</button>
|
|
830
|
-
<h1>{result.data ?? 'default'}</h1>
|
|
831
|
-
</div>
|
|
832
|
-
)
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
render(() => (
|
|
836
|
-
<QueryClientProvider client={queryClient}>
|
|
837
|
-
<Suspense fallback="Loading...">
|
|
838
|
-
<Page />
|
|
839
|
-
</Suspense>
|
|
840
|
-
</QueryClientProvider>
|
|
841
|
-
))
|
|
842
|
-
|
|
843
|
-
expect(screen.queryByText('Loading...')).toBeNull()
|
|
844
|
-
expect(screen.getByRole('heading').textContent).toBe('default')
|
|
845
|
-
await sleep(5)
|
|
846
|
-
fireEvent.click(screen.getByRole('button', { name: /fire/i }))
|
|
847
|
-
await waitFor(() => screen.getByText('Loading...'))
|
|
848
|
-
|
|
849
|
-
await waitFor(() => {
|
|
850
|
-
expect(screen.getByRole('heading').textContent).toBe('data')
|
|
851
|
-
})
|
|
852
|
-
})
|
|
853
|
-
|
|
854
808
|
it('should error catched in error boundary without infinite loop', async () => {
|
|
855
809
|
const key = queryKey()
|
|
856
810
|
|
package/src/createBaseQuery.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function createBaseQuery<
|
|
|
31
31
|
Observer: typeof QueryObserver,
|
|
32
32
|
): QueryObserverResult<TData, TError> {
|
|
33
33
|
const queryClient = useQueryClient({ context: options.context })
|
|
34
|
-
|
|
34
|
+
const emptyData = Symbol('empty')
|
|
35
35
|
const defaultedOptions = queryClient.defaultQueryOptions(options)
|
|
36
36
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
37
37
|
const observer = new Observer(queryClient, defaultedOptions)
|
|
@@ -45,6 +45,9 @@ export function createBaseQuery<
|
|
|
45
45
|
() => {
|
|
46
46
|
return new Promise((resolve) => {
|
|
47
47
|
if (!(state.isFetching && state.isLoading)) {
|
|
48
|
+
if (unwrap(state.data) === emptyData) {
|
|
49
|
+
resolve(undefined)
|
|
50
|
+
}
|
|
48
51
|
resolve(unwrap(state.data))
|
|
49
52
|
}
|
|
50
53
|
})
|
|
@@ -61,7 +64,15 @@ export function createBaseQuery<
|
|
|
61
64
|
const unsubscribe = observer.subscribe((result) => {
|
|
62
65
|
taskQueue.push(() => {
|
|
63
66
|
batch(() => {
|
|
64
|
-
|
|
67
|
+
const unwrappedResult = { ...unwrap(result) }
|
|
68
|
+
if (unwrappedResult.data === undefined) {
|
|
69
|
+
// This is a hack to prevent Solid
|
|
70
|
+
// from deleting the data property when it is `undefined`
|
|
71
|
+
// ref: https://www.solidjs.com/docs/latest/api#updating-stores
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
unwrappedResult.data = emptyData
|
|
74
|
+
}
|
|
75
|
+
setState(unwrap(unwrappedResult))
|
|
65
76
|
mutate(() => unwrap(result.data))
|
|
66
77
|
refetch()
|
|
67
78
|
})
|
|
@@ -110,7 +121,7 @@ export function createBaseQuery<
|
|
|
110
121
|
target: QueryObserverResult<TData, TError>,
|
|
111
122
|
prop: keyof QueryObserverResult<TData, TError>,
|
|
112
123
|
): any {
|
|
113
|
-
if (prop === 'data'
|
|
124
|
+
if (prop === 'data') {
|
|
114
125
|
return dataResource()
|
|
115
126
|
}
|
|
116
127
|
return Reflect.get(target, prop)
|