@tanstack/solid-query 6.0.0-rc.4 → 6.0.0-rc.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/dev.cjs +22 -29
- package/build/dev.js +24 -31
- package/build/index.cjs +22 -29
- package/build/index.js +24 -31
- package/package.json +10 -7
- package/src/QueryClientProvider.tsx +6 -14
- package/src/cacheAggregate.ts +2 -3
- package/src/useBaseQuery.ts +42 -39
package/build/dev.cjs
CHANGED
|
@@ -47,8 +47,8 @@ exports.useQueryClient = (queryClient) => {
|
|
|
47
47
|
return client();
|
|
48
48
|
};
|
|
49
49
|
function serializeCacheOnServer(client) {
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
50
|
+
const writer = web.getHydrationWriter();
|
|
51
|
+
if (!writer || !writer.async || !solidJs.isHydratable()) return;
|
|
52
52
|
const cache = client.getQueryCache();
|
|
53
53
|
const shouldDehydrateQuery = client.getDefaultOptions().dehydrate?.shouldDehydrateQuery;
|
|
54
54
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -58,7 +58,7 @@ function serializeCacheOnServer(client) {
|
|
|
58
58
|
const state = query.state;
|
|
59
59
|
if (state.status === "success") {
|
|
60
60
|
seen.add(query.queryHash);
|
|
61
|
-
|
|
61
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, {
|
|
62
62
|
data: state.data,
|
|
63
63
|
t: state.dataUpdatedAt
|
|
64
64
|
});
|
|
@@ -66,7 +66,7 @@ function serializeCacheOnServer(client) {
|
|
|
66
66
|
const promise = query.promise;
|
|
67
67
|
if (!promise) return;
|
|
68
68
|
seen.add(query.queryHash);
|
|
69
|
-
|
|
69
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, promise.then(() => ({
|
|
70
70
|
data: query.state.data,
|
|
71
71
|
t: query.state.dataUpdatedAt
|
|
72
72
|
})));
|
|
@@ -141,7 +141,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
141
141
|
() => defaultedOptions(),
|
|
142
142
|
(opts) => observer.setOptions(opts)
|
|
143
143
|
);
|
|
144
|
-
const hydratedMount =
|
|
144
|
+
const hydratedMount = solidJs.isHydrating();
|
|
145
145
|
const [version, setVersion] = solidJs.createSignal(0, { ownedWrite: true });
|
|
146
146
|
const [primed, setPrimed] = solidJs.createSignal(!hydratedMount, {
|
|
147
147
|
ownedWrite: true
|
|
@@ -215,29 +215,19 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
215
215
|
};
|
|
216
216
|
if (!isServer2) {
|
|
217
217
|
cacheSub = activeClient.getQueryCache().subscribe(onCacheEvent);
|
|
218
|
-
const sc = solidJs.sharedConfig;
|
|
219
218
|
const registryKey = HYDRATION_KEY_PREFIX + solidJs.untrack(defaultedOptions).queryHash;
|
|
220
|
-
const primeAndAttach = (
|
|
221
|
-
prime(
|
|
219
|
+
const primeAndAttach = (entry2) => {
|
|
220
|
+
prime(entry2);
|
|
222
221
|
setPrimed(true);
|
|
223
222
|
attach();
|
|
224
223
|
};
|
|
225
224
|
const settle = hydratedMount ? primeAndAttach : prime;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
else if (typeof entry.then === "function")
|
|
233
|
-
entry.then(settle, () => settle());
|
|
234
|
-
else settle(entry);
|
|
235
|
-
} else {
|
|
236
|
-
settle(entry);
|
|
237
|
-
}
|
|
238
|
-
} else if (hydratedMount) {
|
|
239
|
-
primeAndAttach();
|
|
240
|
-
}
|
|
225
|
+
const entry = web.takeHydrationValue(registryKey);
|
|
226
|
+
if (entry?.status === "resolved") settle(entry.value);
|
|
227
|
+
else if (entry?.status === "rejected") settle();
|
|
228
|
+
else if (entry?.status === "pending")
|
|
229
|
+
entry.promise.then(settle, () => settle());
|
|
230
|
+
else if (hydratedMount) primeAndAttach();
|
|
241
231
|
if (!hydratedMount) {
|
|
242
232
|
solidJs.createRenderEffect(
|
|
243
233
|
() => isRestoring(),
|
|
@@ -254,8 +244,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
254
244
|
cacheSub = null;
|
|
255
245
|
});
|
|
256
246
|
}
|
|
257
|
-
const
|
|
258
|
-
version();
|
|
247
|
+
const lookupQuery = () => {
|
|
259
248
|
const c = client();
|
|
260
249
|
syncClient(c);
|
|
261
250
|
const cache = c.getQueryCache();
|
|
@@ -267,6 +256,10 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
267
256
|
if (lastQuery?.queryHash === opts.queryHash) return lastQuery;
|
|
268
257
|
return lastQuery = cache.build(c, opts);
|
|
269
258
|
};
|
|
259
|
+
const query = () => {
|
|
260
|
+
version();
|
|
261
|
+
return lookupQuery();
|
|
262
|
+
};
|
|
270
263
|
const isEnabled = () => {
|
|
271
264
|
const opts = defaultedOptions();
|
|
272
265
|
const enabled = typeof opts.enabled === "function" ? opts.enabled(solidJs.untrack(query)) : opts.enabled;
|
|
@@ -312,7 +305,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
312
305
|
}
|
|
313
306
|
if (state.data !== void 0) return wrap(state.data);
|
|
314
307
|
if (isEnabled()) {
|
|
315
|
-
if (
|
|
308
|
+
if (solidJs.isHydrating()) {
|
|
316
309
|
return NEVER;
|
|
317
310
|
}
|
|
318
311
|
if (!primed()) {
|
|
@@ -344,7 +337,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
344
337
|
(draft) => {
|
|
345
338
|
Object.assign(draft, metaFrom(query().state));
|
|
346
339
|
},
|
|
347
|
-
solidJs.untrack(() => metaFrom(
|
|
340
|
+
solidJs.untrack(() => metaFrom(lookupQuery().state))
|
|
348
341
|
);
|
|
349
342
|
const meta = isServer2 ? new Proxy({}, {
|
|
350
343
|
get: (_, key) => serverMeta()[key]
|
|
@@ -357,7 +350,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
357
350
|
return solidJs.untrack(query).state.errorUpdateCount;
|
|
358
351
|
}
|
|
359
352
|
} : solidJs.untrack(() => {
|
|
360
|
-
const state =
|
|
353
|
+
const state = lookupQuery().state;
|
|
361
354
|
return {
|
|
362
355
|
dataUpdateCount: state.dataUpdateCount,
|
|
363
356
|
errorUpdateCount: state.errorUpdateCount
|
|
@@ -489,7 +482,7 @@ async function dehydrateSettled(client, options) {
|
|
|
489
482
|
}
|
|
490
483
|
var isServer3 = typeof window === "undefined";
|
|
491
484
|
function createCacheAggregate(subscribe, read, empty) {
|
|
492
|
-
const hydratedMount =
|
|
485
|
+
const hydratedMount = solidJs.isHydrating();
|
|
493
486
|
const [durable, setDurable] = solidJs.createSignal(
|
|
494
487
|
hydratedMount || isServer3 ? empty : solidJs.untrack(() => read(empty)),
|
|
495
488
|
{ ownedWrite: true }
|
package/build/dev.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { noop, QueryClient as QueryClient$1, hydrate, dehydrate, shouldThrowError, InfiniteQueryObserver, QueryObserver, replaceEqualDeep } from '@tanstack/query-core';
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
|
-
import { createContext, useContext, onCleanup, createMemo, createOptimistic, createSignal, action, createRenderEffect, untrack, repeat, $TRACK,
|
|
4
|
-
import { createComponent, REVALIDATE_HEADER } from '@solidjs/web';
|
|
3
|
+
import { createContext, useContext, onCleanup, createMemo, createOptimistic, createSignal, action, createRenderEffect, untrack, repeat, $TRACK, isHydratable, isHydrating, createEffect, createProjection, runWithOwner, isPending, resolve } from 'solid-js';
|
|
4
|
+
import { createComponent, getHydrationWriter, REVALIDATE_HEADER, takeHydrationValue } from '@solidjs/web';
|
|
5
5
|
import { subscribeFlightData } from '@solidjs/web/server-functions';
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
@@ -46,8 +46,8 @@ var useQueryClient = (queryClient) => {
|
|
|
46
46
|
return client();
|
|
47
47
|
};
|
|
48
48
|
function serializeCacheOnServer(client) {
|
|
49
|
-
const
|
|
50
|
-
if (!
|
|
49
|
+
const writer = getHydrationWriter();
|
|
50
|
+
if (!writer || !writer.async || !isHydratable()) return;
|
|
51
51
|
const cache = client.getQueryCache();
|
|
52
52
|
const shouldDehydrateQuery = client.getDefaultOptions().dehydrate?.shouldDehydrateQuery;
|
|
53
53
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -57,7 +57,7 @@ function serializeCacheOnServer(client) {
|
|
|
57
57
|
const state = query.state;
|
|
58
58
|
if (state.status === "success") {
|
|
59
59
|
seen.add(query.queryHash);
|
|
60
|
-
|
|
60
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, {
|
|
61
61
|
data: state.data,
|
|
62
62
|
t: state.dataUpdatedAt
|
|
63
63
|
});
|
|
@@ -65,7 +65,7 @@ function serializeCacheOnServer(client) {
|
|
|
65
65
|
const promise = query.promise;
|
|
66
66
|
if (!promise) return;
|
|
67
67
|
seen.add(query.queryHash);
|
|
68
|
-
|
|
68
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, promise.then(() => ({
|
|
69
69
|
data: query.state.data,
|
|
70
70
|
t: query.state.dataUpdatedAt
|
|
71
71
|
})));
|
|
@@ -140,7 +140,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
140
140
|
() => defaultedOptions(),
|
|
141
141
|
(opts) => observer.setOptions(opts)
|
|
142
142
|
);
|
|
143
|
-
const hydratedMount =
|
|
143
|
+
const hydratedMount = isHydrating();
|
|
144
144
|
const [version, setVersion] = createSignal(0, { ownedWrite: true });
|
|
145
145
|
const [primed, setPrimed] = createSignal(!hydratedMount, {
|
|
146
146
|
ownedWrite: true
|
|
@@ -214,29 +214,19 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
214
214
|
};
|
|
215
215
|
if (!isServer2) {
|
|
216
216
|
cacheSub = activeClient.getQueryCache().subscribe(onCacheEvent);
|
|
217
|
-
const sc = sharedConfig;
|
|
218
217
|
const registryKey = HYDRATION_KEY_PREFIX + untrack(defaultedOptions).queryHash;
|
|
219
|
-
const primeAndAttach = (
|
|
220
|
-
prime(
|
|
218
|
+
const primeAndAttach = (entry2) => {
|
|
219
|
+
prime(entry2);
|
|
221
220
|
setPrimed(true);
|
|
222
221
|
attach();
|
|
223
222
|
};
|
|
224
223
|
const settle = hydratedMount ? primeAndAttach : prime;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
else if (typeof entry.then === "function")
|
|
232
|
-
entry.then(settle, () => settle());
|
|
233
|
-
else settle(entry);
|
|
234
|
-
} else {
|
|
235
|
-
settle(entry);
|
|
236
|
-
}
|
|
237
|
-
} else if (hydratedMount) {
|
|
238
|
-
primeAndAttach();
|
|
239
|
-
}
|
|
224
|
+
const entry = takeHydrationValue(registryKey);
|
|
225
|
+
if (entry?.status === "resolved") settle(entry.value);
|
|
226
|
+
else if (entry?.status === "rejected") settle();
|
|
227
|
+
else if (entry?.status === "pending")
|
|
228
|
+
entry.promise.then(settle, () => settle());
|
|
229
|
+
else if (hydratedMount) primeAndAttach();
|
|
240
230
|
if (!hydratedMount) {
|
|
241
231
|
createRenderEffect(
|
|
242
232
|
() => isRestoring(),
|
|
@@ -253,8 +243,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
253
243
|
cacheSub = null;
|
|
254
244
|
});
|
|
255
245
|
}
|
|
256
|
-
const
|
|
257
|
-
version();
|
|
246
|
+
const lookupQuery = () => {
|
|
258
247
|
const c = client();
|
|
259
248
|
syncClient(c);
|
|
260
249
|
const cache = c.getQueryCache();
|
|
@@ -266,6 +255,10 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
266
255
|
if (lastQuery?.queryHash === opts.queryHash) return lastQuery;
|
|
267
256
|
return lastQuery = cache.build(c, opts);
|
|
268
257
|
};
|
|
258
|
+
const query = () => {
|
|
259
|
+
version();
|
|
260
|
+
return lookupQuery();
|
|
261
|
+
};
|
|
269
262
|
const isEnabled = () => {
|
|
270
263
|
const opts = defaultedOptions();
|
|
271
264
|
const enabled = typeof opts.enabled === "function" ? opts.enabled(untrack(query)) : opts.enabled;
|
|
@@ -311,7 +304,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
311
304
|
}
|
|
312
305
|
if (state.data !== void 0) return wrap(state.data);
|
|
313
306
|
if (isEnabled()) {
|
|
314
|
-
if (
|
|
307
|
+
if (isHydrating()) {
|
|
315
308
|
return NEVER;
|
|
316
309
|
}
|
|
317
310
|
if (!primed()) {
|
|
@@ -343,7 +336,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
343
336
|
(draft) => {
|
|
344
337
|
Object.assign(draft, metaFrom(query().state));
|
|
345
338
|
},
|
|
346
|
-
untrack(() => metaFrom(
|
|
339
|
+
untrack(() => metaFrom(lookupQuery().state))
|
|
347
340
|
);
|
|
348
341
|
const meta = isServer2 ? new Proxy({}, {
|
|
349
342
|
get: (_, key) => serverMeta()[key]
|
|
@@ -356,7 +349,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
356
349
|
return untrack(query).state.errorUpdateCount;
|
|
357
350
|
}
|
|
358
351
|
} : untrack(() => {
|
|
359
|
-
const state =
|
|
352
|
+
const state = lookupQuery().state;
|
|
360
353
|
return {
|
|
361
354
|
dataUpdateCount: state.dataUpdateCount,
|
|
362
355
|
errorUpdateCount: state.errorUpdateCount
|
|
@@ -488,7 +481,7 @@ async function dehydrateSettled(client, options) {
|
|
|
488
481
|
}
|
|
489
482
|
var isServer3 = typeof window === "undefined";
|
|
490
483
|
function createCacheAggregate(subscribe, read, empty) {
|
|
491
|
-
const hydratedMount =
|
|
484
|
+
const hydratedMount = isHydrating();
|
|
492
485
|
const [durable, setDurable] = createSignal(
|
|
493
486
|
hydratedMount || isServer3 ? empty : untrack(() => read(empty)),
|
|
494
487
|
{ ownedWrite: true }
|
package/build/index.cjs
CHANGED
|
@@ -47,8 +47,8 @@ exports.useQueryClient = (queryClient) => {
|
|
|
47
47
|
return client();
|
|
48
48
|
};
|
|
49
49
|
function serializeCacheOnServer(client) {
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
50
|
+
const writer = web.getHydrationWriter();
|
|
51
|
+
if (!writer || !writer.async || !solidJs.isHydratable()) return;
|
|
52
52
|
const cache = client.getQueryCache();
|
|
53
53
|
const shouldDehydrateQuery = client.getDefaultOptions().dehydrate?.shouldDehydrateQuery;
|
|
54
54
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -58,7 +58,7 @@ function serializeCacheOnServer(client) {
|
|
|
58
58
|
const state = query.state;
|
|
59
59
|
if (state.status === "success") {
|
|
60
60
|
seen.add(query.queryHash);
|
|
61
|
-
|
|
61
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, {
|
|
62
62
|
data: state.data,
|
|
63
63
|
t: state.dataUpdatedAt
|
|
64
64
|
});
|
|
@@ -66,7 +66,7 @@ function serializeCacheOnServer(client) {
|
|
|
66
66
|
const promise = query.promise;
|
|
67
67
|
if (!promise) return;
|
|
68
68
|
seen.add(query.queryHash);
|
|
69
|
-
|
|
69
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, promise.then(() => ({
|
|
70
70
|
data: query.state.data,
|
|
71
71
|
t: query.state.dataUpdatedAt
|
|
72
72
|
})));
|
|
@@ -141,7 +141,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
141
141
|
() => defaultedOptions(),
|
|
142
142
|
(opts) => observer.setOptions(opts)
|
|
143
143
|
);
|
|
144
|
-
const hydratedMount =
|
|
144
|
+
const hydratedMount = solidJs.isHydrating();
|
|
145
145
|
const [version, setVersion] = solidJs.createSignal(0, { ownedWrite: true });
|
|
146
146
|
const [primed, setPrimed] = solidJs.createSignal(!hydratedMount, {
|
|
147
147
|
ownedWrite: true
|
|
@@ -215,29 +215,19 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
215
215
|
};
|
|
216
216
|
if (!isServer2) {
|
|
217
217
|
cacheSub = activeClient.getQueryCache().subscribe(onCacheEvent);
|
|
218
|
-
const sc = solidJs.sharedConfig;
|
|
219
218
|
const registryKey = HYDRATION_KEY_PREFIX + solidJs.untrack(defaultedOptions).queryHash;
|
|
220
|
-
const primeAndAttach = (
|
|
221
|
-
prime(
|
|
219
|
+
const primeAndAttach = (entry2) => {
|
|
220
|
+
prime(entry2);
|
|
222
221
|
setPrimed(true);
|
|
223
222
|
attach();
|
|
224
223
|
};
|
|
225
224
|
const settle = hydratedMount ? primeAndAttach : prime;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
else if (typeof entry.then === "function")
|
|
233
|
-
entry.then(settle, () => settle());
|
|
234
|
-
else settle(entry);
|
|
235
|
-
} else {
|
|
236
|
-
settle(entry);
|
|
237
|
-
}
|
|
238
|
-
} else if (hydratedMount) {
|
|
239
|
-
primeAndAttach();
|
|
240
|
-
}
|
|
225
|
+
const entry = web.takeHydrationValue(registryKey);
|
|
226
|
+
if (entry?.status === "resolved") settle(entry.value);
|
|
227
|
+
else if (entry?.status === "rejected") settle();
|
|
228
|
+
else if (entry?.status === "pending")
|
|
229
|
+
entry.promise.then(settle, () => settle());
|
|
230
|
+
else if (hydratedMount) primeAndAttach();
|
|
241
231
|
if (!hydratedMount) {
|
|
242
232
|
solidJs.createRenderEffect(
|
|
243
233
|
() => isRestoring(),
|
|
@@ -254,8 +244,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
254
244
|
cacheSub = null;
|
|
255
245
|
});
|
|
256
246
|
}
|
|
257
|
-
const
|
|
258
|
-
version();
|
|
247
|
+
const lookupQuery = () => {
|
|
259
248
|
const c = client();
|
|
260
249
|
syncClient(c);
|
|
261
250
|
const cache = c.getQueryCache();
|
|
@@ -267,6 +256,10 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
267
256
|
if (lastQuery?.queryHash === opts.queryHash) return lastQuery;
|
|
268
257
|
return lastQuery = cache.build(c, opts);
|
|
269
258
|
};
|
|
259
|
+
const query = () => {
|
|
260
|
+
version();
|
|
261
|
+
return lookupQuery();
|
|
262
|
+
};
|
|
270
263
|
const isEnabled = () => {
|
|
271
264
|
const opts = defaultedOptions();
|
|
272
265
|
const enabled = typeof opts.enabled === "function" ? opts.enabled(solidJs.untrack(query)) : opts.enabled;
|
|
@@ -312,7 +305,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
312
305
|
}
|
|
313
306
|
if (state.data !== void 0) return wrap(state.data);
|
|
314
307
|
if (isEnabled()) {
|
|
315
|
-
if (
|
|
308
|
+
if (solidJs.isHydrating()) {
|
|
316
309
|
return NEVER;
|
|
317
310
|
}
|
|
318
311
|
if (!primed()) {
|
|
@@ -344,7 +337,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
344
337
|
(draft) => {
|
|
345
338
|
Object.assign(draft, metaFrom(query().state));
|
|
346
339
|
},
|
|
347
|
-
solidJs.untrack(() => metaFrom(
|
|
340
|
+
solidJs.untrack(() => metaFrom(lookupQuery().state))
|
|
348
341
|
);
|
|
349
342
|
const meta = isServer2 ? new Proxy({}, {
|
|
350
343
|
get: (_, key) => serverMeta()[key]
|
|
@@ -357,7 +350,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
357
350
|
return solidJs.untrack(query).state.errorUpdateCount;
|
|
358
351
|
}
|
|
359
352
|
} : solidJs.untrack(() => {
|
|
360
|
-
const state =
|
|
353
|
+
const state = lookupQuery().state;
|
|
361
354
|
return {
|
|
362
355
|
dataUpdateCount: state.dataUpdateCount,
|
|
363
356
|
errorUpdateCount: state.errorUpdateCount
|
|
@@ -489,7 +482,7 @@ async function dehydrateSettled(client, options) {
|
|
|
489
482
|
}
|
|
490
483
|
var isServer3 = typeof window === "undefined";
|
|
491
484
|
function createCacheAggregate(subscribe, read, empty) {
|
|
492
|
-
const hydratedMount =
|
|
485
|
+
const hydratedMount = solidJs.isHydrating();
|
|
493
486
|
const [durable, setDurable] = solidJs.createSignal(
|
|
494
487
|
hydratedMount || isServer3 ? empty : solidJs.untrack(() => read(empty)),
|
|
495
488
|
{ ownedWrite: true }
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { noop, QueryClient as QueryClient$1, hydrate, dehydrate, shouldThrowError, InfiniteQueryObserver, QueryObserver, replaceEqualDeep } from '@tanstack/query-core';
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
|
-
import { createContext, useContext, onCleanup, createMemo, createOptimistic, createSignal, action, createRenderEffect, untrack, repeat, $TRACK,
|
|
4
|
-
import { createComponent, REVALIDATE_HEADER } from '@solidjs/web';
|
|
3
|
+
import { createContext, useContext, onCleanup, createMemo, createOptimistic, createSignal, action, createRenderEffect, untrack, repeat, $TRACK, isHydratable, isHydrating, createEffect, createProjection, runWithOwner, isPending, resolve } from 'solid-js';
|
|
4
|
+
import { createComponent, getHydrationWriter, REVALIDATE_HEADER, takeHydrationValue } from '@solidjs/web';
|
|
5
5
|
import { subscribeFlightData } from '@solidjs/web/server-functions';
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
@@ -46,8 +46,8 @@ var useQueryClient = (queryClient) => {
|
|
|
46
46
|
return client();
|
|
47
47
|
};
|
|
48
48
|
function serializeCacheOnServer(client) {
|
|
49
|
-
const
|
|
50
|
-
if (!
|
|
49
|
+
const writer = getHydrationWriter();
|
|
50
|
+
if (!writer || !writer.async || !isHydratable()) return;
|
|
51
51
|
const cache = client.getQueryCache();
|
|
52
52
|
const shouldDehydrateQuery = client.getDefaultOptions().dehydrate?.shouldDehydrateQuery;
|
|
53
53
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -57,7 +57,7 @@ function serializeCacheOnServer(client) {
|
|
|
57
57
|
const state = query.state;
|
|
58
58
|
if (state.status === "success") {
|
|
59
59
|
seen.add(query.queryHash);
|
|
60
|
-
|
|
60
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, {
|
|
61
61
|
data: state.data,
|
|
62
62
|
t: state.dataUpdatedAt
|
|
63
63
|
});
|
|
@@ -65,7 +65,7 @@ function serializeCacheOnServer(client) {
|
|
|
65
65
|
const promise = query.promise;
|
|
66
66
|
if (!promise) return;
|
|
67
67
|
seen.add(query.queryHash);
|
|
68
|
-
|
|
68
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, promise.then(() => ({
|
|
69
69
|
data: query.state.data,
|
|
70
70
|
t: query.state.dataUpdatedAt
|
|
71
71
|
})));
|
|
@@ -140,7 +140,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
140
140
|
() => defaultedOptions(),
|
|
141
141
|
(opts) => observer.setOptions(opts)
|
|
142
142
|
);
|
|
143
|
-
const hydratedMount =
|
|
143
|
+
const hydratedMount = isHydrating();
|
|
144
144
|
const [version, setVersion] = createSignal(0, { ownedWrite: true });
|
|
145
145
|
const [primed, setPrimed] = createSignal(!hydratedMount, {
|
|
146
146
|
ownedWrite: true
|
|
@@ -214,29 +214,19 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
214
214
|
};
|
|
215
215
|
if (!isServer2) {
|
|
216
216
|
cacheSub = activeClient.getQueryCache().subscribe(onCacheEvent);
|
|
217
|
-
const sc = sharedConfig;
|
|
218
217
|
const registryKey = HYDRATION_KEY_PREFIX + untrack(defaultedOptions).queryHash;
|
|
219
|
-
const primeAndAttach = (
|
|
220
|
-
prime(
|
|
218
|
+
const primeAndAttach = (entry2) => {
|
|
219
|
+
prime(entry2);
|
|
221
220
|
setPrimed(true);
|
|
222
221
|
attach();
|
|
223
222
|
};
|
|
224
223
|
const settle = hydratedMount ? primeAndAttach : prime;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
else if (typeof entry.then === "function")
|
|
232
|
-
entry.then(settle, () => settle());
|
|
233
|
-
else settle(entry);
|
|
234
|
-
} else {
|
|
235
|
-
settle(entry);
|
|
236
|
-
}
|
|
237
|
-
} else if (hydratedMount) {
|
|
238
|
-
primeAndAttach();
|
|
239
|
-
}
|
|
224
|
+
const entry = takeHydrationValue(registryKey);
|
|
225
|
+
if (entry?.status === "resolved") settle(entry.value);
|
|
226
|
+
else if (entry?.status === "rejected") settle();
|
|
227
|
+
else if (entry?.status === "pending")
|
|
228
|
+
entry.promise.then(settle, () => settle());
|
|
229
|
+
else if (hydratedMount) primeAndAttach();
|
|
240
230
|
if (!hydratedMount) {
|
|
241
231
|
createRenderEffect(
|
|
242
232
|
() => isRestoring(),
|
|
@@ -253,8 +243,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
253
243
|
cacheSub = null;
|
|
254
244
|
});
|
|
255
245
|
}
|
|
256
|
-
const
|
|
257
|
-
version();
|
|
246
|
+
const lookupQuery = () => {
|
|
258
247
|
const c = client();
|
|
259
248
|
syncClient(c);
|
|
260
249
|
const cache = c.getQueryCache();
|
|
@@ -266,6 +255,10 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
266
255
|
if (lastQuery?.queryHash === opts.queryHash) return lastQuery;
|
|
267
256
|
return lastQuery = cache.build(c, opts);
|
|
268
257
|
};
|
|
258
|
+
const query = () => {
|
|
259
|
+
version();
|
|
260
|
+
return lookupQuery();
|
|
261
|
+
};
|
|
269
262
|
const isEnabled = () => {
|
|
270
263
|
const opts = defaultedOptions();
|
|
271
264
|
const enabled = typeof opts.enabled === "function" ? opts.enabled(untrack(query)) : opts.enabled;
|
|
@@ -311,7 +304,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
311
304
|
}
|
|
312
305
|
if (state.data !== void 0) return wrap(state.data);
|
|
313
306
|
if (isEnabled()) {
|
|
314
|
-
if (
|
|
307
|
+
if (isHydrating()) {
|
|
315
308
|
return NEVER;
|
|
316
309
|
}
|
|
317
310
|
if (!primed()) {
|
|
@@ -343,7 +336,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
343
336
|
(draft) => {
|
|
344
337
|
Object.assign(draft, metaFrom(query().state));
|
|
345
338
|
},
|
|
346
|
-
untrack(() => metaFrom(
|
|
339
|
+
untrack(() => metaFrom(lookupQuery().state))
|
|
347
340
|
);
|
|
348
341
|
const meta = isServer2 ? new Proxy({}, {
|
|
349
342
|
get: (_, key) => serverMeta()[key]
|
|
@@ -356,7 +349,7 @@ function useBaseQueryLayer(options, Observer, queryClient) {
|
|
|
356
349
|
return untrack(query).state.errorUpdateCount;
|
|
357
350
|
}
|
|
358
351
|
} : untrack(() => {
|
|
359
|
-
const state =
|
|
352
|
+
const state = lookupQuery().state;
|
|
360
353
|
return {
|
|
361
354
|
dataUpdateCount: state.dataUpdateCount,
|
|
362
355
|
errorUpdateCount: state.errorUpdateCount
|
|
@@ -488,7 +481,7 @@ async function dehydrateSettled(client, options) {
|
|
|
488
481
|
}
|
|
489
482
|
var isServer3 = typeof window === "undefined";
|
|
490
483
|
function createCacheAggregate(subscribe, read, empty) {
|
|
491
|
-
const hydratedMount =
|
|
484
|
+
const hydratedMount = isHydrating();
|
|
492
485
|
const [durable, setDurable] = createSignal(
|
|
493
486
|
hydratedMount || isServer3 ? empty : untrack(() => read(empty)),
|
|
494
487
|
{ ownedWrite: true }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "6.0.0-rc.
|
|
3
|
+
"version": "6.0.0-rc.5",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,18 +51,21 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@babel/core": "^7.28.0",
|
|
53
53
|
"@babel/preset-typescript": "^7.18.6",
|
|
54
|
+
"@solidjs/babel-plugin": "^2.0.0-rc.13",
|
|
54
55
|
"@solidjs/testing-library": "^0.8.10",
|
|
55
|
-
"@solidjs/vite-plugin": "^3.0.0-next.
|
|
56
|
-
"@solidjs/web": "^2.0.0-rc.
|
|
57
|
-
"
|
|
56
|
+
"@solidjs/vite-plugin": "^3.0.0-next.46",
|
|
57
|
+
"@solidjs/web": "^2.0.0-rc.13",
|
|
58
|
+
"@vitest/coverage-istanbul": "4.0.6",
|
|
58
59
|
"npm-run-all2": "^5.0.0",
|
|
59
|
-
"solid-js": "^2.0.0-rc.
|
|
60
|
+
"solid-js": "^2.0.0-rc.13",
|
|
60
61
|
"tsup-preset-solid": "^2.2.0",
|
|
62
|
+
"vite": "^8.3.0",
|
|
63
|
+
"vitest": "^4.0.18",
|
|
61
64
|
"@tanstack/query-test-utils": "0.0.0"
|
|
62
65
|
},
|
|
63
66
|
"peerDependencies": {
|
|
64
|
-
"@solidjs/web": ">=2.0.0-rc.
|
|
65
|
-
"solid-js": ">=2.0.0-rc.
|
|
67
|
+
"@solidjs/web": ">=2.0.0-rc.13 <3.0.0",
|
|
68
|
+
"solid-js": ">=2.0.0-rc.13 <3.0.0"
|
|
66
69
|
},
|
|
67
70
|
"scripts": {
|
|
68
71
|
"clean": "premove ./build ./coverage ./dist-ts",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createContext,
|
|
2
|
-
import { REVALIDATE_HEADER } from '@solidjs/web'
|
|
1
|
+
import { createContext, isHydratable, onCleanup, useContext } from 'solid-js'
|
|
2
|
+
import { REVALIDATE_HEADER, getHydrationWriter } from '@solidjs/web'
|
|
3
3
|
import { hydrate } from '@tanstack/query-core'
|
|
4
4
|
import { subscribeFlightData } from '@solidjs/web/server-functions'
|
|
5
5
|
import type { DehydratedState, Query } from '@tanstack/query-core'
|
|
@@ -148,16 +148,8 @@ export type QueryClientProviderProps = {
|
|
|
148
148
|
* serialize, so seroval's cross-reference dedupe emits it once.
|
|
149
149
|
*/
|
|
150
150
|
function serializeCacheOnServer(client: QueryClient): void {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
context?: {
|
|
154
|
-
async?: boolean
|
|
155
|
-
noHydrate?: boolean
|
|
156
|
-
serialize: (key: string, value: unknown) => void
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
).context
|
|
160
|
-
if (!ctx || !ctx.async || ctx.noHydrate) return
|
|
151
|
+
const writer = getHydrationWriter()
|
|
152
|
+
if (!writer || !writer.async || !isHydratable()) return
|
|
161
153
|
|
|
162
154
|
const cache = client.getQueryCache()
|
|
163
155
|
// The standard dehydrate filter gates the wire here too, so apps keep
|
|
@@ -175,7 +167,7 @@ function serializeCacheOnServer(client: QueryClient): void {
|
|
|
175
167
|
const state = query.state
|
|
176
168
|
if (state.status === 'success') {
|
|
177
169
|
seen.add(query.queryHash)
|
|
178
|
-
|
|
170
|
+
writer.write(HYDRATION_KEY_PREFIX + query.queryHash, {
|
|
179
171
|
data: state.data,
|
|
180
172
|
t: state.dataUpdatedAt,
|
|
181
173
|
})
|
|
@@ -185,7 +177,7 @@ function serializeCacheOnServer(client: QueryClient): void {
|
|
|
185
177
|
const promise = query.promise as Promise<unknown> | undefined
|
|
186
178
|
if (!promise) return
|
|
187
179
|
seen.add(query.queryHash)
|
|
188
|
-
|
|
180
|
+
writer.write(
|
|
189
181
|
HYDRATION_KEY_PREFIX + query.queryHash,
|
|
190
182
|
promise.then(() => ({
|
|
191
183
|
data: query.state.data,
|
package/src/cacheAggregate.ts
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
createEffect,
|
|
3
3
|
createOptimistic,
|
|
4
4
|
createSignal,
|
|
5
|
+
isHydrating,
|
|
5
6
|
onCleanup,
|
|
6
|
-
sharedConfig,
|
|
7
7
|
untrack,
|
|
8
8
|
} from 'solid-js'
|
|
9
9
|
import type { Accessor } from 'solid-js'
|
|
@@ -47,8 +47,7 @@ export function createCacheAggregate<T>(
|
|
|
47
47
|
read: (prev: T) => T,
|
|
48
48
|
empty: T,
|
|
49
49
|
): Accessor<T> {
|
|
50
|
-
const hydratedMount =
|
|
51
|
-
!isServer && (sharedConfig as { hydrating?: boolean }).hydrating === true
|
|
50
|
+
const hydratedMount = isHydrating()
|
|
52
51
|
|
|
53
52
|
// Cast: createSignal's value overload excludes functions (a function
|
|
54
53
|
// argument means a compute); aggregate values are counts and arrays.
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -4,13 +4,14 @@ import {
|
|
|
4
4
|
createProjection,
|
|
5
5
|
createRenderEffect,
|
|
6
6
|
createSignal,
|
|
7
|
+
isHydrating,
|
|
7
8
|
isPending as isValuePending,
|
|
8
9
|
onCleanup,
|
|
9
10
|
resolve,
|
|
10
11
|
runWithOwner,
|
|
11
|
-
sharedConfig,
|
|
12
12
|
untrack,
|
|
13
13
|
} from 'solid-js'
|
|
14
|
+
import { takeHydrationValue } from '@solidjs/web'
|
|
14
15
|
import { HYDRATION_KEY_PREFIX, useQueryClient } from './QueryClientProvider'
|
|
15
16
|
import { useIsRestoring } from './isRestoring'
|
|
16
17
|
import type { UseBaseQueryOptions, UseBaseQueryResult } from './types'
|
|
@@ -166,12 +167,10 @@ export function useBaseQueryLayer<
|
|
|
166
167
|
)
|
|
167
168
|
|
|
168
169
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* has no such field — undefined there, and unused.)
|
|
170
|
+
* Solid's own "this component is being hydrated" answer, captured at
|
|
171
|
+
* setup. Always false on the server.
|
|
172
172
|
*/
|
|
173
|
-
const hydratedMount =
|
|
174
|
-
!isServer && (sharedConfig as { hydrating?: boolean }).hydrating === true
|
|
173
|
+
const hydratedMount = isHydrating()
|
|
175
174
|
|
|
176
175
|
/**
|
|
177
176
|
* One version signal per hook, bumped by cache events for this query hash.
|
|
@@ -336,10 +335,6 @@ export function useBaseQueryLayer<
|
|
|
336
335
|
|
|
337
336
|
if (!isServer) {
|
|
338
337
|
cacheSub = activeClient.getQueryCache().subscribe(onCacheEvent)
|
|
339
|
-
const sc = sharedConfig as unknown as {
|
|
340
|
-
has?: (id: string) => boolean
|
|
341
|
-
load?: (id: string) => any
|
|
342
|
-
}
|
|
343
338
|
const registryKey =
|
|
344
339
|
HYDRATION_KEY_PREFIX + untrack(defaultedOptions).queryHash
|
|
345
340
|
const primeAndAttach = (entry?: Partial<HydratedEntry> | null) => {
|
|
@@ -348,24 +343,12 @@ export function useBaseQueryLayer<
|
|
|
348
343
|
attach()
|
|
349
344
|
}
|
|
350
345
|
const settle = hydratedMount ? primeAndAttach : prime
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// ones are plain thenable refs that land with their chunk.
|
|
358
|
-
if (entry.s === 1) settle(entry.v)
|
|
359
|
-
else if (entry.s === 2) settle()
|
|
360
|
-
else if (typeof entry.then === 'function')
|
|
361
|
-
entry.then(settle, () => settle())
|
|
362
|
-
else settle(entry)
|
|
363
|
-
} else {
|
|
364
|
-
settle(entry)
|
|
365
|
-
}
|
|
366
|
-
} else if (hydratedMount) {
|
|
367
|
-
primeAndAttach()
|
|
368
|
-
}
|
|
346
|
+
const entry = takeHydrationValue<Partial<HydratedEntry> | null>(registryKey)
|
|
347
|
+
if (entry?.status === 'resolved') settle(entry.value)
|
|
348
|
+
else if (entry?.status === 'rejected') settle()
|
|
349
|
+
else if (entry?.status === 'pending')
|
|
350
|
+
entry.promise.then(settle, () => settle())
|
|
351
|
+
else if (hydratedMount) primeAndAttach()
|
|
369
352
|
if (!hydratedMount) {
|
|
370
353
|
createRenderEffect(
|
|
371
354
|
() => isRestoring(),
|
|
@@ -383,8 +366,26 @@ export function useBaseQueryLayer<
|
|
|
383
366
|
})
|
|
384
367
|
}
|
|
385
368
|
|
|
386
|
-
|
|
387
|
-
|
|
369
|
+
/**
|
|
370
|
+
* The cache entry for the current options, without the `version` read —
|
|
371
|
+
* for the setup-time snapshots below (`metaProjection`'s seed,
|
|
372
|
+
* `mountedAt`), which run in whatever computation is instantiating this
|
|
373
|
+
* component. Under hydration that matters: priming bumps `version`
|
|
374
|
+
* during setup, and Solid holds a write made during the hydration pass —
|
|
375
|
+
* a computation in the pass that reads the written signal, tracked or
|
|
376
|
+
* not, is served the pre-write snapshot and replays at release. For the
|
|
377
|
+
* hook's own derived nodes that replay is the takeover. For the
|
|
378
|
+
* instantiating computation (a boundary's children, a `<Show>` branch)
|
|
379
|
+
* it is a remount: the hydrated component is disposed and re-created as
|
|
380
|
+
* a client render, and the server value stops holding the DOM. So the
|
|
381
|
+
* snapshots read the cache, never the signal.
|
|
382
|
+
*/
|
|
383
|
+
const lookupQuery = (): Query<
|
|
384
|
+
TQueryFnData,
|
|
385
|
+
TError,
|
|
386
|
+
TQueryData,
|
|
387
|
+
TQueryKey
|
|
388
|
+
> => {
|
|
388
389
|
const c = client()
|
|
389
390
|
syncClient(c)
|
|
390
391
|
const cache = c.getQueryCache()
|
|
@@ -396,6 +397,10 @@ export function useBaseQueryLayer<
|
|
|
396
397
|
if (lastQuery?.queryHash === opts.queryHash) return lastQuery
|
|
397
398
|
return (lastQuery = cache.build(c, opts as any) as any)
|
|
398
399
|
}
|
|
400
|
+
const query = (): Query<TQueryFnData, TError, TQueryData, TQueryKey> => {
|
|
401
|
+
version()
|
|
402
|
+
return lookupQuery()
|
|
403
|
+
}
|
|
399
404
|
|
|
400
405
|
const isEnabled = () => {
|
|
401
406
|
const opts = defaultedOptions()
|
|
@@ -522,7 +527,7 @@ export function useBaseQueryLayer<
|
|
|
522
527
|
* priming; if a fetch is genuinely needed, the post-priming observer
|
|
523
528
|
* attach issues it outside the window.
|
|
524
529
|
*/
|
|
525
|
-
if (
|
|
530
|
+
if (isHydrating()) {
|
|
526
531
|
return NEVER
|
|
527
532
|
}
|
|
528
533
|
/**
|
|
@@ -593,12 +598,10 @@ export function useBaseQueryLayer<
|
|
|
593
598
|
* first-paint exception in `computeData`.
|
|
594
599
|
*
|
|
595
600
|
* Default ('server') hydration semantics: the serialized value owns the
|
|
596
|
-
* node
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
* Requires solid-js > 2.0.0-rc.3 (before the takeover fix, a mid-stream
|
|
601
|
-
* divergence was lost rather than deferred).
|
|
601
|
+
* node while it hydrates. Outside every still-pending streamed boundary,
|
|
602
|
+
* a cache write commits immediately. Under a pending boundary it waits
|
|
603
|
+
* for that boundary to resume, which hydrates against the server
|
|
604
|
+
* snapshot.
|
|
602
605
|
*/
|
|
603
606
|
const dataStore = createProjection<{ value: TData }>(
|
|
604
607
|
(draft) => computeData(draft.value as TData | undefined),
|
|
@@ -644,7 +647,7 @@ export function useBaseQueryLayer<
|
|
|
644
647
|
(draft) => {
|
|
645
648
|
Object.assign(draft, metaFrom(query().state))
|
|
646
649
|
},
|
|
647
|
-
untrack(() => metaFrom(
|
|
650
|
+
untrack(() => metaFrom(lookupQuery().state)),
|
|
648
651
|
)
|
|
649
652
|
const meta = isServer
|
|
650
653
|
? new Proxy({} as MetaState, {
|
|
@@ -668,7 +671,7 @@ export function useBaseQueryLayer<
|
|
|
668
671
|
},
|
|
669
672
|
}
|
|
670
673
|
: untrack(() => {
|
|
671
|
-
const state =
|
|
674
|
+
const state = lookupQuery().state
|
|
672
675
|
return {
|
|
673
676
|
dataUpdateCount: state.dataUpdateCount,
|
|
674
677
|
errorUpdateCount: state.errorUpdateCount,
|