@tanstack/solid-query 6.0.0-beta.3 → 6.0.0-beta.5
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/_tsup-dts-rollup.d.cts +39 -68
- package/build/_tsup-dts-rollup.d.ts +39 -68
- package/build/dev.cjs +85 -56
- package/build/dev.d.cts +4 -7
- package/build/dev.d.ts +4 -7
- package/build/dev.js +86 -57
- package/build/index.cjs +85 -56
- package/build/index.d.cts +4 -7
- package/build/index.d.ts +4 -7
- package/build/index.js +86 -57
- package/package.json +6 -6
- package/src/QueryClientProvider.tsx +1 -1
- package/src/index.ts +3 -3
- package/src/infiniteQueryOptions.ts +3 -15
- package/src/mutationOptions.ts +7 -7
- package/src/queryOptions.ts +3 -3
- package/src/types.ts +6 -6
- package/src/useBaseQuery.ts +113 -44
- package/src/useIsFetching.ts +1 -1
- package/src/useIsMutating.ts +1 -1
- package/src/useMutation.ts +12 -5
- package/src/useMutationState.ts +1 -1
- package/src/useQueries.ts +23 -18
package/build/index.cjs
CHANGED
|
@@ -84,10 +84,10 @@ var hydratableObserverResult = (query, result) => {
|
|
|
84
84
|
return obj;
|
|
85
85
|
};
|
|
86
86
|
function useBaseQuery(options, Observer, queryClient) {
|
|
87
|
-
const client = solidJs.
|
|
87
|
+
const [client] = solidJs.createSignal(() => exports.useQueryClient(queryClient?.()));
|
|
88
88
|
const isRestoring = exports.useIsRestoring();
|
|
89
89
|
let unsubscribeQueued = false;
|
|
90
|
-
const defaultedOptions = solidJs.
|
|
90
|
+
const [defaultedOptions] = solidJs.createSignal(() => {
|
|
91
91
|
const defaultOptions = client().defaultQueryOptions(options());
|
|
92
92
|
defaultOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
93
93
|
defaultOptions.structuralSharing = false;
|
|
@@ -99,11 +99,11 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
99
99
|
return defaultOptions;
|
|
100
100
|
});
|
|
101
101
|
const observer = solidJs.untrack(() => new Observer(client(), defaultedOptions()));
|
|
102
|
-
const trackedDefaultedOptions = solidJs.
|
|
102
|
+
const [trackedDefaultedOptions] = solidJs.createSignal(() => defaultedOptions());
|
|
103
103
|
solidJs.createRenderEffect(
|
|
104
104
|
() => trackedDefaultedOptions(),
|
|
105
105
|
(opts) => {
|
|
106
|
-
observer.setOptions(opts);
|
|
106
|
+
solidJs.runWithOwner(null, () => observer.setOptions(opts));
|
|
107
107
|
}
|
|
108
108
|
);
|
|
109
109
|
let observerResult = solidJs.untrack(
|
|
@@ -137,8 +137,8 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
137
137
|
return observer.subscribe((result) => {
|
|
138
138
|
const previousResult = observerResult;
|
|
139
139
|
observerResult = result;
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
solidJs.runWithOwner(null, () => {
|
|
141
|
+
setStateWithReconciliation(result);
|
|
142
142
|
if (unsubscribe && !disposed && (previousResult.isLoading !== result.isLoading || previousResult.isError !== result.isError)) {
|
|
143
143
|
try {
|
|
144
144
|
solidJs.refresh(queryResource);
|
|
@@ -164,41 +164,58 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
164
164
|
let unsubscribe = null;
|
|
165
165
|
let disposed = false;
|
|
166
166
|
let resolver = null;
|
|
167
|
-
const queryResource = solidJs.
|
|
168
|
-
()
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
167
|
+
const [queryResource] = solidJs.createSignal(() => {
|
|
168
|
+
const opts = trackedDefaultedOptions();
|
|
169
|
+
const restoring = isRestoring();
|
|
170
|
+
if (isServer) {
|
|
171
|
+
const cached = observer.getOptimisticResult(opts);
|
|
172
|
+
if (!cached.isLoading) {
|
|
173
|
+
observerResult = cached;
|
|
174
|
+
solidJs.runWithOwner(null, () => {
|
|
175
|
+
setStateWithReconciliation(cached);
|
|
176
|
+
});
|
|
177
|
+
return hydratableObserverResult(
|
|
178
|
+
observer.getCurrentQuery(),
|
|
179
|
+
cached
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return new Promise((resolve, reject) => {
|
|
184
|
+
resolver = resolve;
|
|
185
|
+
if (isServer) {
|
|
186
|
+
unsubscribe = createServerSubscriber((data) => {
|
|
187
|
+
resolve(data);
|
|
188
|
+
}, reject);
|
|
189
|
+
} else if (!unsubscribe && !restoring) {
|
|
190
|
+
unsubscribe = createClientSubscriber();
|
|
191
|
+
}
|
|
192
|
+
const currentResult = observer.getOptimisticResult(opts);
|
|
193
|
+
observerResult = currentResult;
|
|
194
|
+
solidJs.runWithOwner(null, () => {
|
|
182
195
|
if (currentResult.isError && !currentResult.isFetching && !restoring && queryCore.shouldThrowError(opts.throwOnError, [
|
|
183
196
|
currentResult.error,
|
|
184
197
|
observer.getCurrentQuery()
|
|
185
198
|
])) {
|
|
186
199
|
setStateWithReconciliation(currentResult);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!currentResult.isLoading) {
|
|
190
|
-
resolver = null;
|
|
191
|
-
setStateWithReconciliation(currentResult);
|
|
192
|
-
return resolve(
|
|
193
|
-
hydratableObserverResult(observer.getCurrentQuery(), currentResult)
|
|
194
|
-
);
|
|
200
|
+
reject(currentResult.error);
|
|
201
|
+
return;
|
|
195
202
|
}
|
|
196
|
-
|
|
203
|
+
setStateWithReconciliation(currentResult);
|
|
197
204
|
});
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
205
|
+
if (currentResult.isError && !currentResult.isFetching && !restoring && queryCore.shouldThrowError(opts.throwOnError, [
|
|
206
|
+
currentResult.error,
|
|
207
|
+
observer.getCurrentQuery()
|
|
208
|
+
])) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!currentResult.isLoading) {
|
|
212
|
+
resolver = null;
|
|
213
|
+
return resolve(
|
|
214
|
+
hydratableObserverResult(observer.getCurrentQuery(), currentResult)
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
202
219
|
solidJs.onCleanup(() => {
|
|
203
220
|
disposed = true;
|
|
204
221
|
if (isServer && solidJs.isPending(queryResource)) {
|
|
@@ -227,6 +244,12 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
227
244
|
if (typeof prop === "symbol") {
|
|
228
245
|
return Reflect.get(target, prop, receiver);
|
|
229
246
|
}
|
|
247
|
+
if (isServer) {
|
|
248
|
+
const resolved = queryResource();
|
|
249
|
+
if (prop in resolved) {
|
|
250
|
+
return Reflect.get(resolved, prop);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
230
253
|
if (errorPassthroughProps.has(prop)) {
|
|
231
254
|
return Reflect.get(target, prop, receiver);
|
|
232
255
|
}
|
|
@@ -280,11 +303,13 @@ function useMutation(options, queryClient) {
|
|
|
280
303
|
mutateAsync: initialResult.mutate
|
|
281
304
|
});
|
|
282
305
|
const unsubscribe = observer.subscribe((result) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
306
|
+
solidJs.runWithOwner(null, () => {
|
|
307
|
+
setState(() => ({
|
|
308
|
+
...result,
|
|
309
|
+
mutate,
|
|
310
|
+
mutateAsync: result.mutate
|
|
311
|
+
}));
|
|
312
|
+
});
|
|
288
313
|
});
|
|
289
314
|
solidJs.onCleanup(unsubscribe);
|
|
290
315
|
solidJs.createRenderEffect(
|
|
@@ -336,14 +361,16 @@ function useQueries(queriesOptions, queryClient) {
|
|
|
336
361
|
() => {
|
|
337
362
|
if (!isRestoring()) {
|
|
338
363
|
unsubscribe = observer.subscribe((result) => {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
364
|
+
solidJs.runWithOwner(null, () => {
|
|
365
|
+
setState(
|
|
366
|
+
solidJs.reconcile(
|
|
367
|
+
[...result],
|
|
368
|
+
// Use a key function that returns undefined so reconcile
|
|
369
|
+
// uses positional matching and recursively updates nested properties
|
|
370
|
+
() => void 0
|
|
371
|
+
)
|
|
372
|
+
);
|
|
373
|
+
});
|
|
347
374
|
});
|
|
348
375
|
}
|
|
349
376
|
},
|
|
@@ -355,12 +382,14 @@ function useQueries(queriesOptions, queryClient) {
|
|
|
355
382
|
});
|
|
356
383
|
solidJs.createMemo(() => {
|
|
357
384
|
const queries = defaultedQueries();
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
385
|
+
solidJs.runWithOwner(null, () => {
|
|
386
|
+
observer.setQueries(
|
|
387
|
+
queries,
|
|
388
|
+
queriesOptions().combine ? {
|
|
389
|
+
combine: queriesOptions().combine
|
|
390
|
+
} : void 0
|
|
391
|
+
);
|
|
392
|
+
});
|
|
364
393
|
return queries;
|
|
365
394
|
});
|
|
366
395
|
return state;
|
|
@@ -380,7 +409,7 @@ function useIsFetching(filters, queryClient) {
|
|
|
380
409
|
const queryCache = solidJs.createMemo(() => client().getQueryCache());
|
|
381
410
|
const [fetches, setFetches] = solidJs.createSignal(
|
|
382
411
|
solidJs.untrack(() => client().isFetching(filters?.())),
|
|
383
|
-
{
|
|
412
|
+
{ ownedWrite: true }
|
|
384
413
|
);
|
|
385
414
|
const unsubscribe = solidJs.untrack(
|
|
386
415
|
() => queryCache().subscribe(() => {
|
|
@@ -405,7 +434,7 @@ function useIsMutating(filters, queryClient) {
|
|
|
405
434
|
const mutationCache = solidJs.createMemo(() => client().getMutationCache());
|
|
406
435
|
const [mutations, setMutations] = solidJs.createSignal(
|
|
407
436
|
solidJs.untrack(() => client().isMutating(filters?.())),
|
|
408
|
-
{
|
|
437
|
+
{ ownedWrite: true }
|
|
409
438
|
);
|
|
410
439
|
const unsubscribe = solidJs.untrack(
|
|
411
440
|
() => mutationCache().subscribe((_result) => {
|
|
@@ -425,7 +454,7 @@ function useMutationState(options = () => ({}), queryClient) {
|
|
|
425
454
|
const mutationCache = solidJs.createMemo(() => client().getMutationCache());
|
|
426
455
|
const [result, setResult] = solidJs.createSignal(
|
|
427
456
|
solidJs.untrack(() => getResult(mutationCache(), options())),
|
|
428
|
-
{
|
|
457
|
+
{ ownedWrite: true }
|
|
429
458
|
);
|
|
430
459
|
const unsubscribe = solidJs.untrack(
|
|
431
460
|
() => mutationCache().subscribe(() => {
|
package/build/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { DefinedUseBaseQueryResult } from './_tsup-dts-rollup.cjs';
|
|
2
2
|
export { DefinedUseInfiniteQueryResult } from './_tsup-dts-rollup.cjs';
|
|
3
3
|
export { DefinedUseQueryResult } from './_tsup-dts-rollup.cjs';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
4
|
+
export { InfiniteQueryOptions } from './_tsup-dts-rollup.cjs';
|
|
5
|
+
export { MutationOptions } from './_tsup-dts-rollup.cjs';
|
|
6
|
+
export { QueryOptions } from './_tsup-dts-rollup.cjs';
|
|
7
7
|
export { UseBaseMutationResult } from './_tsup-dts-rollup.cjs';
|
|
8
8
|
export { UseBaseQueryOptions } from './_tsup-dts-rollup.cjs';
|
|
9
9
|
export { UseBaseQueryResult } from './_tsup-dts-rollup.cjs';
|
|
@@ -111,7 +111,6 @@ export { NonUndefinedGuard } from './_tsup-dts-rollup.cjs';
|
|
|
111
111
|
export { DistributiveOmit } from './_tsup-dts-rollup.cjs';
|
|
112
112
|
export { OmitKeyof } from './_tsup-dts-rollup.cjs';
|
|
113
113
|
export { Override } from './_tsup-dts-rollup.cjs';
|
|
114
|
-
export { NoInfer } from './_tsup-dts-rollup.cjs';
|
|
115
114
|
export { Register } from './_tsup-dts-rollup.cjs';
|
|
116
115
|
export { DefaultError } from './_tsup-dts-rollup.cjs';
|
|
117
116
|
export { QueryKey } from './_tsup-dts-rollup.cjs';
|
|
@@ -126,7 +125,7 @@ export { InferErrorFromTag } from './_tsup-dts-rollup.cjs';
|
|
|
126
125
|
export { QueryFunction } from './_tsup-dts-rollup.cjs';
|
|
127
126
|
export { StaleTime } from './_tsup-dts-rollup.cjs';
|
|
128
127
|
export { StaleTimeFunction } from './_tsup-dts-rollup.cjs';
|
|
129
|
-
export {
|
|
128
|
+
export { QueryBooleanOption } from './_tsup-dts-rollup.cjs';
|
|
130
129
|
export { QueryPersister } from './_tsup-dts-rollup.cjs';
|
|
131
130
|
export { QueryFunctionContext } from './_tsup-dts-rollup.cjs';
|
|
132
131
|
export { InitialDataFunction } from './_tsup-dts-rollup.cjs';
|
|
@@ -139,7 +138,6 @@ export { InfiniteData } from './_tsup-dts-rollup.cjs';
|
|
|
139
138
|
export { QueryMeta } from './_tsup-dts-rollup.cjs';
|
|
140
139
|
export { NetworkMode } from './_tsup-dts-rollup.cjs';
|
|
141
140
|
export { NotifyOnChangeProps } from './_tsup-dts-rollup.cjs';
|
|
142
|
-
export { QueryOptions } from './_tsup-dts-rollup.cjs';
|
|
143
141
|
export { InitialPageParam } from './_tsup-dts-rollup.cjs';
|
|
144
142
|
export { InfiniteQueryPageParamsOptions } from './_tsup-dts-rollup.cjs';
|
|
145
143
|
export { ThrowOnError } from './_tsup-dts-rollup.cjs';
|
|
@@ -184,7 +182,6 @@ export { MutationScope } from './_tsup-dts-rollup.cjs';
|
|
|
184
182
|
export { MutationMeta } from './_tsup-dts-rollup.cjs';
|
|
185
183
|
export { MutationFunctionContext } from './_tsup-dts-rollup.cjs';
|
|
186
184
|
export { MutationFunction } from './_tsup-dts-rollup.cjs';
|
|
187
|
-
export { MutationOptions } from './_tsup-dts-rollup.cjs';
|
|
188
185
|
export { MutationObserverOptions } from './_tsup-dts-rollup.cjs';
|
|
189
186
|
export { MutateOptions } from './_tsup-dts-rollup.cjs';
|
|
190
187
|
export { MutateFunction } from './_tsup-dts-rollup.cjs';
|
package/build/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { DefinedUseBaseQueryResult } from './_tsup-dts-rollup.js';
|
|
2
2
|
export { DefinedUseInfiniteQueryResult } from './_tsup-dts-rollup.js';
|
|
3
3
|
export { DefinedUseQueryResult } from './_tsup-dts-rollup.js';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
4
|
+
export { InfiniteQueryOptions } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { MutationOptions } from './_tsup-dts-rollup.js';
|
|
6
|
+
export { QueryOptions } from './_tsup-dts-rollup.js';
|
|
7
7
|
export { UseBaseMutationResult } from './_tsup-dts-rollup.js';
|
|
8
8
|
export { UseBaseQueryOptions } from './_tsup-dts-rollup.js';
|
|
9
9
|
export { UseBaseQueryResult } from './_tsup-dts-rollup.js';
|
|
@@ -111,7 +111,6 @@ export { NonUndefinedGuard } from './_tsup-dts-rollup.js';
|
|
|
111
111
|
export { DistributiveOmit } from './_tsup-dts-rollup.js';
|
|
112
112
|
export { OmitKeyof } from './_tsup-dts-rollup.js';
|
|
113
113
|
export { Override } from './_tsup-dts-rollup.js';
|
|
114
|
-
export { NoInfer } from './_tsup-dts-rollup.js';
|
|
115
114
|
export { Register } from './_tsup-dts-rollup.js';
|
|
116
115
|
export { DefaultError } from './_tsup-dts-rollup.js';
|
|
117
116
|
export { QueryKey } from './_tsup-dts-rollup.js';
|
|
@@ -126,7 +125,7 @@ export { InferErrorFromTag } from './_tsup-dts-rollup.js';
|
|
|
126
125
|
export { QueryFunction } from './_tsup-dts-rollup.js';
|
|
127
126
|
export { StaleTime } from './_tsup-dts-rollup.js';
|
|
128
127
|
export { StaleTimeFunction } from './_tsup-dts-rollup.js';
|
|
129
|
-
export {
|
|
128
|
+
export { QueryBooleanOption } from './_tsup-dts-rollup.js';
|
|
130
129
|
export { QueryPersister } from './_tsup-dts-rollup.js';
|
|
131
130
|
export { QueryFunctionContext } from './_tsup-dts-rollup.js';
|
|
132
131
|
export { InitialDataFunction } from './_tsup-dts-rollup.js';
|
|
@@ -139,7 +138,6 @@ export { InfiniteData } from './_tsup-dts-rollup.js';
|
|
|
139
138
|
export { QueryMeta } from './_tsup-dts-rollup.js';
|
|
140
139
|
export { NetworkMode } from './_tsup-dts-rollup.js';
|
|
141
140
|
export { NotifyOnChangeProps } from './_tsup-dts-rollup.js';
|
|
142
|
-
export { QueryOptions } from './_tsup-dts-rollup.js';
|
|
143
141
|
export { InitialPageParam } from './_tsup-dts-rollup.js';
|
|
144
142
|
export { InfiniteQueryPageParamsOptions } from './_tsup-dts-rollup.js';
|
|
145
143
|
export { ThrowOnError } from './_tsup-dts-rollup.js';
|
|
@@ -184,7 +182,6 @@ export { MutationScope } from './_tsup-dts-rollup.js';
|
|
|
184
182
|
export { MutationMeta } from './_tsup-dts-rollup.js';
|
|
185
183
|
export { MutationFunctionContext } from './_tsup-dts-rollup.js';
|
|
186
184
|
export { MutationFunction } from './_tsup-dts-rollup.js';
|
|
187
|
-
export { MutationOptions } from './_tsup-dts-rollup.js';
|
|
188
185
|
export { MutationObserverOptions } from './_tsup-dts-rollup.js';
|
|
189
186
|
export { MutateOptions } from './_tsup-dts-rollup.js';
|
|
190
187
|
export { MutateFunction } from './_tsup-dts-rollup.js';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MutationObserver, shouldThrowError, QueriesObserver, QueryClient as QueryClient$1, replaceEqualDeep, noop, notifyManager, QueryObserver, InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
|
-
import { createContext, useContext, onCleanup, createMemo, untrack, createRenderEffect, createStore, merge, createEffect, reconcile, createSignal, isPending, refresh, snapshot } from 'solid-js';
|
|
3
|
+
import { createContext, useContext, onCleanup, createMemo, untrack, createRenderEffect, createStore, runWithOwner, merge, createEffect, reconcile, createSignal, isPending, refresh, snapshot } from 'solid-js';
|
|
4
4
|
import { createComponent } from '@solidjs/web';
|
|
5
5
|
|
|
6
6
|
// src/useQuery.ts
|
|
@@ -83,10 +83,10 @@ var hydratableObserverResult = (query, result) => {
|
|
|
83
83
|
return obj;
|
|
84
84
|
};
|
|
85
85
|
function useBaseQuery(options, Observer, queryClient) {
|
|
86
|
-
const client =
|
|
86
|
+
const [client] = createSignal(() => useQueryClient(queryClient?.()));
|
|
87
87
|
const isRestoring = useIsRestoring();
|
|
88
88
|
let unsubscribeQueued = false;
|
|
89
|
-
const defaultedOptions =
|
|
89
|
+
const [defaultedOptions] = createSignal(() => {
|
|
90
90
|
const defaultOptions = client().defaultQueryOptions(options());
|
|
91
91
|
defaultOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
92
92
|
defaultOptions.structuralSharing = false;
|
|
@@ -98,11 +98,11 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
98
98
|
return defaultOptions;
|
|
99
99
|
});
|
|
100
100
|
const observer = untrack(() => new Observer(client(), defaultedOptions()));
|
|
101
|
-
const trackedDefaultedOptions =
|
|
101
|
+
const [trackedDefaultedOptions] = createSignal(() => defaultedOptions());
|
|
102
102
|
createRenderEffect(
|
|
103
103
|
() => trackedDefaultedOptions(),
|
|
104
104
|
(opts) => {
|
|
105
|
-
observer.setOptions(opts);
|
|
105
|
+
runWithOwner(null, () => observer.setOptions(opts));
|
|
106
106
|
}
|
|
107
107
|
);
|
|
108
108
|
let observerResult = untrack(
|
|
@@ -136,8 +136,8 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
136
136
|
return observer.subscribe((result) => {
|
|
137
137
|
const previousResult = observerResult;
|
|
138
138
|
observerResult = result;
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
runWithOwner(null, () => {
|
|
140
|
+
setStateWithReconciliation(result);
|
|
141
141
|
if (unsubscribe && !disposed && (previousResult.isLoading !== result.isLoading || previousResult.isError !== result.isError)) {
|
|
142
142
|
try {
|
|
143
143
|
refresh(queryResource);
|
|
@@ -163,41 +163,58 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
163
163
|
let unsubscribe = null;
|
|
164
164
|
let disposed = false;
|
|
165
165
|
let resolver = null;
|
|
166
|
-
const queryResource =
|
|
167
|
-
()
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
166
|
+
const [queryResource] = createSignal(() => {
|
|
167
|
+
const opts = trackedDefaultedOptions();
|
|
168
|
+
const restoring = isRestoring();
|
|
169
|
+
if (isServer) {
|
|
170
|
+
const cached = observer.getOptimisticResult(opts);
|
|
171
|
+
if (!cached.isLoading) {
|
|
172
|
+
observerResult = cached;
|
|
173
|
+
runWithOwner(null, () => {
|
|
174
|
+
setStateWithReconciliation(cached);
|
|
175
|
+
});
|
|
176
|
+
return hydratableObserverResult(
|
|
177
|
+
observer.getCurrentQuery(),
|
|
178
|
+
cached
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return new Promise((resolve, reject) => {
|
|
183
|
+
resolver = resolve;
|
|
184
|
+
if (isServer) {
|
|
185
|
+
unsubscribe = createServerSubscriber((data) => {
|
|
186
|
+
resolve(data);
|
|
187
|
+
}, reject);
|
|
188
|
+
} else if (!unsubscribe && !restoring) {
|
|
189
|
+
unsubscribe = createClientSubscriber();
|
|
190
|
+
}
|
|
191
|
+
const currentResult = observer.getOptimisticResult(opts);
|
|
192
|
+
observerResult = currentResult;
|
|
193
|
+
runWithOwner(null, () => {
|
|
181
194
|
if (currentResult.isError && !currentResult.isFetching && !restoring && shouldThrowError(opts.throwOnError, [
|
|
182
195
|
currentResult.error,
|
|
183
196
|
observer.getCurrentQuery()
|
|
184
197
|
])) {
|
|
185
198
|
setStateWithReconciliation(currentResult);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (!currentResult.isLoading) {
|
|
189
|
-
resolver = null;
|
|
190
|
-
setStateWithReconciliation(currentResult);
|
|
191
|
-
return resolve(
|
|
192
|
-
hydratableObserverResult(observer.getCurrentQuery(), currentResult)
|
|
193
|
-
);
|
|
199
|
+
reject(currentResult.error);
|
|
200
|
+
return;
|
|
194
201
|
}
|
|
195
|
-
|
|
202
|
+
setStateWithReconciliation(currentResult);
|
|
196
203
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
if (currentResult.isError && !currentResult.isFetching && !restoring && shouldThrowError(opts.throwOnError, [
|
|
205
|
+
currentResult.error,
|
|
206
|
+
observer.getCurrentQuery()
|
|
207
|
+
])) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (!currentResult.isLoading) {
|
|
211
|
+
resolver = null;
|
|
212
|
+
return resolve(
|
|
213
|
+
hydratableObserverResult(observer.getCurrentQuery(), currentResult)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
201
218
|
onCleanup(() => {
|
|
202
219
|
disposed = true;
|
|
203
220
|
if (isServer && isPending(queryResource)) {
|
|
@@ -226,6 +243,12 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
226
243
|
if (typeof prop === "symbol") {
|
|
227
244
|
return Reflect.get(target, prop, receiver);
|
|
228
245
|
}
|
|
246
|
+
if (isServer) {
|
|
247
|
+
const resolved = queryResource();
|
|
248
|
+
if (prop in resolved) {
|
|
249
|
+
return Reflect.get(resolved, prop);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
229
252
|
if (errorPassthroughProps.has(prop)) {
|
|
230
253
|
return Reflect.get(target, prop, receiver);
|
|
231
254
|
}
|
|
@@ -279,11 +302,13 @@ function useMutation(options, queryClient) {
|
|
|
279
302
|
mutateAsync: initialResult.mutate
|
|
280
303
|
});
|
|
281
304
|
const unsubscribe = observer.subscribe((result) => {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
305
|
+
runWithOwner(null, () => {
|
|
306
|
+
setState(() => ({
|
|
307
|
+
...result,
|
|
308
|
+
mutate,
|
|
309
|
+
mutateAsync: result.mutate
|
|
310
|
+
}));
|
|
311
|
+
});
|
|
287
312
|
});
|
|
288
313
|
onCleanup(unsubscribe);
|
|
289
314
|
createRenderEffect(
|
|
@@ -335,14 +360,16 @@ function useQueries(queriesOptions, queryClient) {
|
|
|
335
360
|
() => {
|
|
336
361
|
if (!isRestoring()) {
|
|
337
362
|
unsubscribe = observer.subscribe((result) => {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
363
|
+
runWithOwner(null, () => {
|
|
364
|
+
setState(
|
|
365
|
+
reconcile(
|
|
366
|
+
[...result],
|
|
367
|
+
// Use a key function that returns undefined so reconcile
|
|
368
|
+
// uses positional matching and recursively updates nested properties
|
|
369
|
+
() => void 0
|
|
370
|
+
)
|
|
371
|
+
);
|
|
372
|
+
});
|
|
346
373
|
});
|
|
347
374
|
}
|
|
348
375
|
},
|
|
@@ -354,12 +381,14 @@ function useQueries(queriesOptions, queryClient) {
|
|
|
354
381
|
});
|
|
355
382
|
createMemo(() => {
|
|
356
383
|
const queries = defaultedQueries();
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
384
|
+
runWithOwner(null, () => {
|
|
385
|
+
observer.setQueries(
|
|
386
|
+
queries,
|
|
387
|
+
queriesOptions().combine ? {
|
|
388
|
+
combine: queriesOptions().combine
|
|
389
|
+
} : void 0
|
|
390
|
+
);
|
|
391
|
+
});
|
|
363
392
|
return queries;
|
|
364
393
|
});
|
|
365
394
|
return state;
|
|
@@ -379,7 +408,7 @@ function useIsFetching(filters, queryClient) {
|
|
|
379
408
|
const queryCache = createMemo(() => client().getQueryCache());
|
|
380
409
|
const [fetches, setFetches] = createSignal(
|
|
381
410
|
untrack(() => client().isFetching(filters?.())),
|
|
382
|
-
{
|
|
411
|
+
{ ownedWrite: true }
|
|
383
412
|
);
|
|
384
413
|
const unsubscribe = untrack(
|
|
385
414
|
() => queryCache().subscribe(() => {
|
|
@@ -404,7 +433,7 @@ function useIsMutating(filters, queryClient) {
|
|
|
404
433
|
const mutationCache = createMemo(() => client().getMutationCache());
|
|
405
434
|
const [mutations, setMutations] = createSignal(
|
|
406
435
|
untrack(() => client().isMutating(filters?.())),
|
|
407
|
-
{
|
|
436
|
+
{ ownedWrite: true }
|
|
408
437
|
);
|
|
409
438
|
const unsubscribe = untrack(
|
|
410
439
|
() => mutationCache().subscribe((_result) => {
|
|
@@ -424,7 +453,7 @@ function useMutationState(options = () => ({}), queryClient) {
|
|
|
424
453
|
const mutationCache = createMemo(() => client().getMutationCache());
|
|
425
454
|
const [result, setResult] = createSignal(
|
|
426
455
|
untrack(() => getResult(mutationCache(), options())),
|
|
427
|
-
{
|
|
456
|
+
{ ownedWrite: true }
|
|
428
457
|
);
|
|
429
458
|
const unsubscribe = untrack(
|
|
430
459
|
() => mutationCache().subscribe(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.5",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,18 +46,18 @@
|
|
|
46
46
|
"!src/__tests__"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@tanstack/query-core": "5.
|
|
49
|
+
"@tanstack/query-core": "5.101.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@babel/core": "^7.28.0",
|
|
53
53
|
"@babel/preset-typescript": "^7.18.6",
|
|
54
54
|
"@solidjs/testing-library": "^0.8.10",
|
|
55
|
-
"@solidjs/web": "2.0.0-beta.
|
|
56
|
-
"babel-preset-solid": "2.0.0-beta.
|
|
55
|
+
"@solidjs/web": "2.0.0-beta.15",
|
|
56
|
+
"babel-preset-solid": "2.0.0-beta.15",
|
|
57
57
|
"npm-run-all2": "^5.0.0",
|
|
58
|
-
"solid-js": "2.0.0-beta.
|
|
58
|
+
"solid-js": "2.0.0-beta.15",
|
|
59
59
|
"tsup-preset-solid": "^2.2.0",
|
|
60
|
-
"vite-plugin-solid": "3.0.0-next.
|
|
60
|
+
"vite-plugin-solid": "3.0.0-next.5",
|
|
61
61
|
"@tanstack/query-test-utils": "0.0.0"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, onCleanup, useContext } from 'solid-js'
|
|
2
2
|
import type { QueryClient } from './QueryClient'
|
|
3
|
-
import type { JSX } from '
|
|
3
|
+
import type { JSX } from '@solidjs/web'
|
|
4
4
|
|
|
5
5
|
export const QueryClientContext = createContext<(() => QueryClient) | null>(
|
|
6
6
|
null,
|
package/src/index.ts
CHANGED
|
@@ -15,9 +15,9 @@ export type {
|
|
|
15
15
|
DefinedUseBaseQueryResult,
|
|
16
16
|
DefinedUseInfiniteQueryResult,
|
|
17
17
|
DefinedUseQueryResult,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
InfiniteQueryOptions,
|
|
19
|
+
MutationOptions,
|
|
20
|
+
QueryOptions,
|
|
21
21
|
UseBaseMutationResult,
|
|
22
22
|
UseBaseQueryOptions,
|
|
23
23
|
UseBaseQueryResult,
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
NonUndefinedGuard,
|
|
6
6
|
QueryKey,
|
|
7
7
|
} from '@tanstack/query-core'
|
|
8
|
-
import type {
|
|
8
|
+
import type { InfiniteQueryOptions } from './types'
|
|
9
9
|
import type { Accessor } from 'solid-js'
|
|
10
10
|
|
|
11
11
|
export type UndefinedInitialDataInfiniteOptions<
|
|
@@ -15,13 +15,7 @@ export type UndefinedInitialDataInfiniteOptions<
|
|
|
15
15
|
TQueryKey extends QueryKey = QueryKey,
|
|
16
16
|
TPageParam = unknown,
|
|
17
17
|
> = Accessor<
|
|
18
|
-
|
|
19
|
-
TQueryFnData,
|
|
20
|
-
TError,
|
|
21
|
-
TData,
|
|
22
|
-
TQueryKey,
|
|
23
|
-
TPageParam
|
|
24
|
-
> & {
|
|
18
|
+
InfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
25
19
|
initialData?: undefined
|
|
26
20
|
}
|
|
27
21
|
>
|
|
@@ -34,13 +28,7 @@ export type DefinedInitialDataInfiniteOptions<
|
|
|
34
28
|
TQueryKey extends QueryKey = QueryKey,
|
|
35
29
|
TPageParam = unknown,
|
|
36
30
|
> = Accessor<
|
|
37
|
-
|
|
38
|
-
TQueryFnData,
|
|
39
|
-
TError,
|
|
40
|
-
TData,
|
|
41
|
-
TQueryKey,
|
|
42
|
-
TPageParam
|
|
43
|
-
> & {
|
|
31
|
+
InfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
44
32
|
initialData:
|
|
45
33
|
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
|
|
46
34
|
| (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
|