@tanstack/solid-query 5.29.0 → 5.30.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/dev.cjs +43 -39
- package/build/dev.js +45 -41
- package/build/index.cjs +43 -39
- package/build/index.js +45 -41
- package/package.json +1 -4
- package/src/createBaseQuery.ts +51 -46
- package/src/index.ts +0 -3
- package/src/setBatchUpdatesFn.ts +0 -4
package/build/dev.cjs
CHANGED
|
@@ -5,8 +5,7 @@ var solidJs = require('solid-js');
|
|
|
5
5
|
var web = require('solid-js/web');
|
|
6
6
|
var store = require('solid-js/store');
|
|
7
7
|
|
|
8
|
-
// src/
|
|
9
|
-
queryCore.notifyManager.setBatchNotifyFunction(solidJs.batch);
|
|
8
|
+
// src/index.ts
|
|
10
9
|
exports.QueryClient = class QueryClient extends queryCore.QueryClient {
|
|
11
10
|
constructor(config = {}) {
|
|
12
11
|
super(config);
|
|
@@ -103,9 +102,8 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
103
102
|
const [observer, setObserver] = solidJs.createSignal(
|
|
104
103
|
new Observer(client(), defaultedOptions())
|
|
105
104
|
);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
105
|
+
let observerResult = observer().getOptimisticResult(defaultedOptions());
|
|
106
|
+
const [state, setState] = store.createStore(observerResult);
|
|
109
107
|
const createServerSubscriber = (resolve, reject) => {
|
|
110
108
|
return observer().subscribe((result) => {
|
|
111
109
|
queryCore.notifyManager.batchCalls(() => {
|
|
@@ -130,32 +128,34 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
130
128
|
const createClientSubscriber = () => {
|
|
131
129
|
const obs = observer();
|
|
132
130
|
return obs.subscribe((result) => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (queryResource()?.data && result.data && !queryResource.loading) {
|
|
136
|
-
setState((store) => {
|
|
137
|
-
return reconcileFn(
|
|
138
|
-
store,
|
|
139
|
-
result,
|
|
140
|
-
reconcileOptions === void 0 ? false : reconcileOptions
|
|
141
|
-
);
|
|
142
|
-
});
|
|
143
|
-
mutate(state);
|
|
144
|
-
} else {
|
|
145
|
-
setState((store) => {
|
|
146
|
-
return reconcileFn(
|
|
147
|
-
store,
|
|
148
|
-
result,
|
|
149
|
-
reconcileOptions === void 0 ? false : reconcileOptions
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
refetch();
|
|
153
|
-
}
|
|
154
|
-
})();
|
|
131
|
+
observerResult = result;
|
|
132
|
+
queueMicrotask(() => refetch());
|
|
155
133
|
});
|
|
156
134
|
};
|
|
135
|
+
function setStateWithReconciliation(res) {
|
|
136
|
+
const reconcileOptions = observer().options.reconcile;
|
|
137
|
+
setState((store) => {
|
|
138
|
+
return reconcileFn(
|
|
139
|
+
store,
|
|
140
|
+
res,
|
|
141
|
+
reconcileOptions === void 0 ? false : reconcileOptions
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function createDeepSignal() {
|
|
146
|
+
return [
|
|
147
|
+
() => state,
|
|
148
|
+
(v) => {
|
|
149
|
+
const unwrapped = store.unwrap(state);
|
|
150
|
+
if (typeof v === "function") {
|
|
151
|
+
v = v(unwrapped);
|
|
152
|
+
}
|
|
153
|
+
setStateWithReconciliation(v);
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
157
|
let unsubscribe = null;
|
|
158
|
-
const [queryResource, { refetch
|
|
158
|
+
const [queryResource, { refetch }] = solidJs.createResource(
|
|
159
159
|
() => {
|
|
160
160
|
const obs = observer();
|
|
161
161
|
return new Promise((resolve, reject) => {
|
|
@@ -165,18 +165,16 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
165
165
|
unsubscribe = createClientSubscriber();
|
|
166
166
|
}
|
|
167
167
|
obs.updateResult();
|
|
168
|
-
if (!
|
|
168
|
+
if (!observerResult.isLoading) {
|
|
169
169
|
const query = obs.getCurrentQuery();
|
|
170
|
-
resolve(hydratableObserverResult(query,
|
|
170
|
+
resolve(hydratableObserverResult(query, observerResult));
|
|
171
|
+
} else {
|
|
172
|
+
setStateWithReconciliation(observerResult);
|
|
171
173
|
}
|
|
172
174
|
});
|
|
173
175
|
},
|
|
174
176
|
{
|
|
175
|
-
|
|
176
|
-
// If initialData is provided, we resolve the resource immediately
|
|
177
|
-
get ssrLoadFrom() {
|
|
178
|
-
return options().initialData ? "initial" : "server";
|
|
179
|
-
},
|
|
177
|
+
storage: createDeepSignal,
|
|
180
178
|
get deferStream() {
|
|
181
179
|
return options().deferStream;
|
|
182
180
|
},
|
|
@@ -203,7 +201,7 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
203
201
|
if (unsubscribe)
|
|
204
202
|
return;
|
|
205
203
|
const newOptions = { ...initialOptions };
|
|
206
|
-
if (initialOptions.staleTime || !initialOptions.initialData) {
|
|
204
|
+
if ((initialOptions.staleTime || !initialOptions.initialData) && info.value) {
|
|
207
205
|
newOptions.refetchOnMount = false;
|
|
208
206
|
}
|
|
209
207
|
observer().setOptions(newOptions);
|
|
@@ -254,7 +252,7 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
254
252
|
[observer, defaultedOptions],
|
|
255
253
|
([obs, opts]) => {
|
|
256
254
|
obs.setOptions(opts);
|
|
257
|
-
|
|
255
|
+
setStateWithReconciliation(obs.getOptimisticResult(opts));
|
|
258
256
|
},
|
|
259
257
|
{ defer: true }
|
|
260
258
|
)
|
|
@@ -275,8 +273,14 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
275
273
|
);
|
|
276
274
|
const handler = {
|
|
277
275
|
get(target, prop) {
|
|
278
|
-
|
|
279
|
-
|
|
276
|
+
if (prop === "data") {
|
|
277
|
+
const opts = observer().options;
|
|
278
|
+
if (opts.placeholderData) {
|
|
279
|
+
return queryResource.latest?.data;
|
|
280
|
+
}
|
|
281
|
+
return queryResource()?.data;
|
|
282
|
+
}
|
|
283
|
+
return Reflect.get(target, prop);
|
|
280
284
|
}
|
|
281
285
|
};
|
|
282
286
|
return new Proxy(state, handler);
|
package/build/dev.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QueryClient as QueryClient$1, MutationObserver, replaceEqualDeep, QueriesObserver, hydrate, QueryObserver, InfiniteQueryObserver, notifyManager } from '@tanstack/query-core';
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
|
-
import {
|
|
3
|
+
import { createContext, useContext, createRenderEffect, onCleanup, createMemo, createSignal, createComputed, on, createEffect, mergeProps, createResource, batch, onMount } from 'solid-js';
|
|
4
4
|
import { createComponent, isServer } from 'solid-js/web';
|
|
5
5
|
import { createStore, unwrap, reconcile } from 'solid-js/store';
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
notifyManager.setBatchNotifyFunction(batch);
|
|
7
|
+
// src/index.ts
|
|
9
8
|
var QueryClient = class extends QueryClient$1 {
|
|
10
9
|
constructor(config = {}) {
|
|
11
10
|
super(config);
|
|
@@ -102,9 +101,8 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
102
101
|
const [observer, setObserver] = createSignal(
|
|
103
102
|
new Observer(client(), defaultedOptions())
|
|
104
103
|
);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
104
|
+
let observerResult = observer().getOptimisticResult(defaultedOptions());
|
|
105
|
+
const [state, setState] = createStore(observerResult);
|
|
108
106
|
const createServerSubscriber = (resolve, reject) => {
|
|
109
107
|
return observer().subscribe((result) => {
|
|
110
108
|
notifyManager.batchCalls(() => {
|
|
@@ -129,32 +127,34 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
129
127
|
const createClientSubscriber = () => {
|
|
130
128
|
const obs = observer();
|
|
131
129
|
return obs.subscribe((result) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (queryResource()?.data && result.data && !queryResource.loading) {
|
|
135
|
-
setState((store) => {
|
|
136
|
-
return reconcileFn(
|
|
137
|
-
store,
|
|
138
|
-
result,
|
|
139
|
-
reconcileOptions === void 0 ? false : reconcileOptions
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
mutate(state);
|
|
143
|
-
} else {
|
|
144
|
-
setState((store) => {
|
|
145
|
-
return reconcileFn(
|
|
146
|
-
store,
|
|
147
|
-
result,
|
|
148
|
-
reconcileOptions === void 0 ? false : reconcileOptions
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
refetch();
|
|
152
|
-
}
|
|
153
|
-
})();
|
|
130
|
+
observerResult = result;
|
|
131
|
+
queueMicrotask(() => refetch());
|
|
154
132
|
});
|
|
155
133
|
};
|
|
134
|
+
function setStateWithReconciliation(res) {
|
|
135
|
+
const reconcileOptions = observer().options.reconcile;
|
|
136
|
+
setState((store) => {
|
|
137
|
+
return reconcileFn(
|
|
138
|
+
store,
|
|
139
|
+
res,
|
|
140
|
+
reconcileOptions === void 0 ? false : reconcileOptions
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function createDeepSignal() {
|
|
145
|
+
return [
|
|
146
|
+
() => state,
|
|
147
|
+
(v) => {
|
|
148
|
+
const unwrapped = unwrap(state);
|
|
149
|
+
if (typeof v === "function") {
|
|
150
|
+
v = v(unwrapped);
|
|
151
|
+
}
|
|
152
|
+
setStateWithReconciliation(v);
|
|
153
|
+
}
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
156
|
let unsubscribe = null;
|
|
157
|
-
const [queryResource, { refetch
|
|
157
|
+
const [queryResource, { refetch }] = createResource(
|
|
158
158
|
() => {
|
|
159
159
|
const obs = observer();
|
|
160
160
|
return new Promise((resolve, reject) => {
|
|
@@ -164,18 +164,16 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
164
164
|
unsubscribe = createClientSubscriber();
|
|
165
165
|
}
|
|
166
166
|
obs.updateResult();
|
|
167
|
-
if (!
|
|
167
|
+
if (!observerResult.isLoading) {
|
|
168
168
|
const query = obs.getCurrentQuery();
|
|
169
|
-
resolve(hydratableObserverResult(query,
|
|
169
|
+
resolve(hydratableObserverResult(query, observerResult));
|
|
170
|
+
} else {
|
|
171
|
+
setStateWithReconciliation(observerResult);
|
|
170
172
|
}
|
|
171
173
|
});
|
|
172
174
|
},
|
|
173
175
|
{
|
|
174
|
-
|
|
175
|
-
// If initialData is provided, we resolve the resource immediately
|
|
176
|
-
get ssrLoadFrom() {
|
|
177
|
-
return options().initialData ? "initial" : "server";
|
|
178
|
-
},
|
|
176
|
+
storage: createDeepSignal,
|
|
179
177
|
get deferStream() {
|
|
180
178
|
return options().deferStream;
|
|
181
179
|
},
|
|
@@ -202,7 +200,7 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
202
200
|
if (unsubscribe)
|
|
203
201
|
return;
|
|
204
202
|
const newOptions = { ...initialOptions };
|
|
205
|
-
if (initialOptions.staleTime || !initialOptions.initialData) {
|
|
203
|
+
if ((initialOptions.staleTime || !initialOptions.initialData) && info.value) {
|
|
206
204
|
newOptions.refetchOnMount = false;
|
|
207
205
|
}
|
|
208
206
|
observer().setOptions(newOptions);
|
|
@@ -253,7 +251,7 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
253
251
|
[observer, defaultedOptions],
|
|
254
252
|
([obs, opts]) => {
|
|
255
253
|
obs.setOptions(opts);
|
|
256
|
-
|
|
254
|
+
setStateWithReconciliation(obs.getOptimisticResult(opts));
|
|
257
255
|
},
|
|
258
256
|
{ defer: true }
|
|
259
257
|
)
|
|
@@ -274,8 +272,14 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
274
272
|
);
|
|
275
273
|
const handler = {
|
|
276
274
|
get(target, prop) {
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
if (prop === "data") {
|
|
276
|
+
const opts = observer().options;
|
|
277
|
+
if (opts.placeholderData) {
|
|
278
|
+
return queryResource.latest?.data;
|
|
279
|
+
}
|
|
280
|
+
return queryResource()?.data;
|
|
281
|
+
}
|
|
282
|
+
return Reflect.get(target, prop);
|
|
279
283
|
}
|
|
280
284
|
};
|
|
281
285
|
return new Proxy(state, handler);
|
package/build/index.cjs
CHANGED
|
@@ -5,8 +5,7 @@ var solidJs = require('solid-js');
|
|
|
5
5
|
var web = require('solid-js/web');
|
|
6
6
|
var store = require('solid-js/store');
|
|
7
7
|
|
|
8
|
-
// src/
|
|
9
|
-
queryCore.notifyManager.setBatchNotifyFunction(solidJs.batch);
|
|
8
|
+
// src/index.ts
|
|
10
9
|
exports.QueryClient = class QueryClient extends queryCore.QueryClient {
|
|
11
10
|
constructor(config = {}) {
|
|
12
11
|
super(config);
|
|
@@ -103,9 +102,8 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
103
102
|
const [observer, setObserver] = solidJs.createSignal(
|
|
104
103
|
new Observer(client(), defaultedOptions())
|
|
105
104
|
);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
105
|
+
let observerResult = observer().getOptimisticResult(defaultedOptions());
|
|
106
|
+
const [state, setState] = store.createStore(observerResult);
|
|
109
107
|
const createServerSubscriber = (resolve, reject) => {
|
|
110
108
|
return observer().subscribe((result) => {
|
|
111
109
|
queryCore.notifyManager.batchCalls(() => {
|
|
@@ -130,32 +128,34 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
130
128
|
const createClientSubscriber = () => {
|
|
131
129
|
const obs = observer();
|
|
132
130
|
return obs.subscribe((result) => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (queryResource()?.data && result.data && !queryResource.loading) {
|
|
136
|
-
setState((store) => {
|
|
137
|
-
return reconcileFn(
|
|
138
|
-
store,
|
|
139
|
-
result,
|
|
140
|
-
reconcileOptions === void 0 ? false : reconcileOptions
|
|
141
|
-
);
|
|
142
|
-
});
|
|
143
|
-
mutate(state);
|
|
144
|
-
} else {
|
|
145
|
-
setState((store) => {
|
|
146
|
-
return reconcileFn(
|
|
147
|
-
store,
|
|
148
|
-
result,
|
|
149
|
-
reconcileOptions === void 0 ? false : reconcileOptions
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
refetch();
|
|
153
|
-
}
|
|
154
|
-
})();
|
|
131
|
+
observerResult = result;
|
|
132
|
+
queueMicrotask(() => refetch());
|
|
155
133
|
});
|
|
156
134
|
};
|
|
135
|
+
function setStateWithReconciliation(res) {
|
|
136
|
+
const reconcileOptions = observer().options.reconcile;
|
|
137
|
+
setState((store) => {
|
|
138
|
+
return reconcileFn(
|
|
139
|
+
store,
|
|
140
|
+
res,
|
|
141
|
+
reconcileOptions === void 0 ? false : reconcileOptions
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function createDeepSignal() {
|
|
146
|
+
return [
|
|
147
|
+
() => state,
|
|
148
|
+
(v) => {
|
|
149
|
+
const unwrapped = store.unwrap(state);
|
|
150
|
+
if (typeof v === "function") {
|
|
151
|
+
v = v(unwrapped);
|
|
152
|
+
}
|
|
153
|
+
setStateWithReconciliation(v);
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
157
|
let unsubscribe = null;
|
|
158
|
-
const [queryResource, { refetch
|
|
158
|
+
const [queryResource, { refetch }] = solidJs.createResource(
|
|
159
159
|
() => {
|
|
160
160
|
const obs = observer();
|
|
161
161
|
return new Promise((resolve, reject) => {
|
|
@@ -165,18 +165,16 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
165
165
|
unsubscribe = createClientSubscriber();
|
|
166
166
|
}
|
|
167
167
|
obs.updateResult();
|
|
168
|
-
if (!
|
|
168
|
+
if (!observerResult.isLoading) {
|
|
169
169
|
const query = obs.getCurrentQuery();
|
|
170
|
-
resolve(hydratableObserverResult(query,
|
|
170
|
+
resolve(hydratableObserverResult(query, observerResult));
|
|
171
|
+
} else {
|
|
172
|
+
setStateWithReconciliation(observerResult);
|
|
171
173
|
}
|
|
172
174
|
});
|
|
173
175
|
},
|
|
174
176
|
{
|
|
175
|
-
|
|
176
|
-
// If initialData is provided, we resolve the resource immediately
|
|
177
|
-
get ssrLoadFrom() {
|
|
178
|
-
return options().initialData ? "initial" : "server";
|
|
179
|
-
},
|
|
177
|
+
storage: createDeepSignal,
|
|
180
178
|
get deferStream() {
|
|
181
179
|
return options().deferStream;
|
|
182
180
|
},
|
|
@@ -203,7 +201,7 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
203
201
|
if (unsubscribe)
|
|
204
202
|
return;
|
|
205
203
|
const newOptions = { ...initialOptions };
|
|
206
|
-
if (initialOptions.staleTime || !initialOptions.initialData) {
|
|
204
|
+
if ((initialOptions.staleTime || !initialOptions.initialData) && info.value) {
|
|
207
205
|
newOptions.refetchOnMount = false;
|
|
208
206
|
}
|
|
209
207
|
observer().setOptions(newOptions);
|
|
@@ -254,7 +252,7 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
254
252
|
[observer, defaultedOptions],
|
|
255
253
|
([obs, opts]) => {
|
|
256
254
|
obs.setOptions(opts);
|
|
257
|
-
|
|
255
|
+
setStateWithReconciliation(obs.getOptimisticResult(opts));
|
|
258
256
|
},
|
|
259
257
|
{ defer: true }
|
|
260
258
|
)
|
|
@@ -275,8 +273,14 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
275
273
|
);
|
|
276
274
|
const handler = {
|
|
277
275
|
get(target, prop) {
|
|
278
|
-
|
|
279
|
-
|
|
276
|
+
if (prop === "data") {
|
|
277
|
+
const opts = observer().options;
|
|
278
|
+
if (opts.placeholderData) {
|
|
279
|
+
return queryResource.latest?.data;
|
|
280
|
+
}
|
|
281
|
+
return queryResource()?.data;
|
|
282
|
+
}
|
|
283
|
+
return Reflect.get(target, prop);
|
|
280
284
|
}
|
|
281
285
|
};
|
|
282
286
|
return new Proxy(state, handler);
|
package/build/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QueryClient as QueryClient$1, MutationObserver, replaceEqualDeep, QueriesObserver, hydrate, QueryObserver, InfiniteQueryObserver, notifyManager } from '@tanstack/query-core';
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
|
-
import {
|
|
3
|
+
import { createContext, useContext, createRenderEffect, onCleanup, createMemo, createSignal, createComputed, on, createEffect, mergeProps, createResource, batch, onMount } from 'solid-js';
|
|
4
4
|
import { createComponent, isServer } from 'solid-js/web';
|
|
5
5
|
import { createStore, unwrap, reconcile } from 'solid-js/store';
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
notifyManager.setBatchNotifyFunction(batch);
|
|
7
|
+
// src/index.ts
|
|
9
8
|
var QueryClient = class extends QueryClient$1 {
|
|
10
9
|
constructor(config = {}) {
|
|
11
10
|
super(config);
|
|
@@ -102,9 +101,8 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
102
101
|
const [observer, setObserver] = createSignal(
|
|
103
102
|
new Observer(client(), defaultedOptions())
|
|
104
103
|
);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
104
|
+
let observerResult = observer().getOptimisticResult(defaultedOptions());
|
|
105
|
+
const [state, setState] = createStore(observerResult);
|
|
108
106
|
const createServerSubscriber = (resolve, reject) => {
|
|
109
107
|
return observer().subscribe((result) => {
|
|
110
108
|
notifyManager.batchCalls(() => {
|
|
@@ -129,32 +127,34 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
129
127
|
const createClientSubscriber = () => {
|
|
130
128
|
const obs = observer();
|
|
131
129
|
return obs.subscribe((result) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (queryResource()?.data && result.data && !queryResource.loading) {
|
|
135
|
-
setState((store) => {
|
|
136
|
-
return reconcileFn(
|
|
137
|
-
store,
|
|
138
|
-
result,
|
|
139
|
-
reconcileOptions === void 0 ? false : reconcileOptions
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
mutate(state);
|
|
143
|
-
} else {
|
|
144
|
-
setState((store) => {
|
|
145
|
-
return reconcileFn(
|
|
146
|
-
store,
|
|
147
|
-
result,
|
|
148
|
-
reconcileOptions === void 0 ? false : reconcileOptions
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
refetch();
|
|
152
|
-
}
|
|
153
|
-
})();
|
|
130
|
+
observerResult = result;
|
|
131
|
+
queueMicrotask(() => refetch());
|
|
154
132
|
});
|
|
155
133
|
};
|
|
134
|
+
function setStateWithReconciliation(res) {
|
|
135
|
+
const reconcileOptions = observer().options.reconcile;
|
|
136
|
+
setState((store) => {
|
|
137
|
+
return reconcileFn(
|
|
138
|
+
store,
|
|
139
|
+
res,
|
|
140
|
+
reconcileOptions === void 0 ? false : reconcileOptions
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function createDeepSignal() {
|
|
145
|
+
return [
|
|
146
|
+
() => state,
|
|
147
|
+
(v) => {
|
|
148
|
+
const unwrapped = unwrap(state);
|
|
149
|
+
if (typeof v === "function") {
|
|
150
|
+
v = v(unwrapped);
|
|
151
|
+
}
|
|
152
|
+
setStateWithReconciliation(v);
|
|
153
|
+
}
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
156
|
let unsubscribe = null;
|
|
157
|
-
const [queryResource, { refetch
|
|
157
|
+
const [queryResource, { refetch }] = createResource(
|
|
158
158
|
() => {
|
|
159
159
|
const obs = observer();
|
|
160
160
|
return new Promise((resolve, reject) => {
|
|
@@ -164,18 +164,16 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
164
164
|
unsubscribe = createClientSubscriber();
|
|
165
165
|
}
|
|
166
166
|
obs.updateResult();
|
|
167
|
-
if (!
|
|
167
|
+
if (!observerResult.isLoading) {
|
|
168
168
|
const query = obs.getCurrentQuery();
|
|
169
|
-
resolve(hydratableObserverResult(query,
|
|
169
|
+
resolve(hydratableObserverResult(query, observerResult));
|
|
170
|
+
} else {
|
|
171
|
+
setStateWithReconciliation(observerResult);
|
|
170
172
|
}
|
|
171
173
|
});
|
|
172
174
|
},
|
|
173
175
|
{
|
|
174
|
-
|
|
175
|
-
// If initialData is provided, we resolve the resource immediately
|
|
176
|
-
get ssrLoadFrom() {
|
|
177
|
-
return options().initialData ? "initial" : "server";
|
|
178
|
-
},
|
|
176
|
+
storage: createDeepSignal,
|
|
179
177
|
get deferStream() {
|
|
180
178
|
return options().deferStream;
|
|
181
179
|
},
|
|
@@ -202,7 +200,7 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
202
200
|
if (unsubscribe)
|
|
203
201
|
return;
|
|
204
202
|
const newOptions = { ...initialOptions };
|
|
205
|
-
if (initialOptions.staleTime || !initialOptions.initialData) {
|
|
203
|
+
if ((initialOptions.staleTime || !initialOptions.initialData) && info.value) {
|
|
206
204
|
newOptions.refetchOnMount = false;
|
|
207
205
|
}
|
|
208
206
|
observer().setOptions(newOptions);
|
|
@@ -253,7 +251,7 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
253
251
|
[observer, defaultedOptions],
|
|
254
252
|
([obs, opts]) => {
|
|
255
253
|
obs.setOptions(opts);
|
|
256
|
-
|
|
254
|
+
setStateWithReconciliation(obs.getOptimisticResult(opts));
|
|
257
255
|
},
|
|
258
256
|
{ defer: true }
|
|
259
257
|
)
|
|
@@ -274,8 +272,14 @@ function createBaseQuery(options, Observer, queryClient) {
|
|
|
274
272
|
);
|
|
275
273
|
const handler = {
|
|
276
274
|
get(target, prop) {
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
if (prop === "data") {
|
|
276
|
+
const opts = observer().options;
|
|
277
|
+
if (opts.placeholderData) {
|
|
278
|
+
return queryResource.latest?.data;
|
|
279
|
+
}
|
|
280
|
+
return queryResource()?.data;
|
|
281
|
+
}
|
|
282
|
+
return Reflect.get(target, prop);
|
|
279
283
|
}
|
|
280
284
|
};
|
|
281
285
|
return new Proxy(state, handler);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.30.0",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,9 +39,6 @@
|
|
|
39
39
|
"default": "./build/index.cjs"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
"sideEffects": [
|
|
43
|
-
"./src/setBatchUpdatesFn.ts"
|
|
44
|
-
],
|
|
45
42
|
"files": [
|
|
46
43
|
"build",
|
|
47
44
|
"src"
|
package/src/createBaseQuery.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { useQueryClient } from './QueryClientProvider'
|
|
|
16
16
|
import { shouldThrowError } from './utils'
|
|
17
17
|
import { useIsRestoring } from './isRestoring'
|
|
18
18
|
import type { CreateBaseQueryOptions } from './types'
|
|
19
|
-
import type { Accessor } from 'solid-js'
|
|
19
|
+
import type { Accessor, Signal } from 'solid-js'
|
|
20
20
|
import type { QueryClient } from './QueryClient'
|
|
21
21
|
import type {
|
|
22
22
|
InfiniteQueryObserverResult,
|
|
@@ -144,9 +144,9 @@ export function createBaseQuery<
|
|
|
144
144
|
new Observer(client(), defaultedOptions()),
|
|
145
145
|
)
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
let observerResult = observer().getOptimisticResult(defaultedOptions())
|
|
148
|
+
const [state, setState] =
|
|
149
|
+
createStore<QueryObserverResult<TData, TError>>(observerResult)
|
|
150
150
|
|
|
151
151
|
const createServerSubscriber = (
|
|
152
152
|
resolve: (
|
|
@@ -180,44 +180,43 @@ export function createBaseQuery<
|
|
|
180
180
|
const createClientSubscriber = () => {
|
|
181
181
|
const obs = observer()
|
|
182
182
|
return obs.subscribe((result) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
mutate(state)
|
|
199
|
-
} else {
|
|
200
|
-
setState((store) => {
|
|
201
|
-
return reconcileFn(
|
|
202
|
-
store,
|
|
203
|
-
result,
|
|
204
|
-
reconcileOptions === undefined ? false : reconcileOptions,
|
|
205
|
-
)
|
|
206
|
-
})
|
|
207
|
-
refetch()
|
|
208
|
-
}
|
|
209
|
-
})()
|
|
183
|
+
observerResult = result
|
|
184
|
+
queueMicrotask(() => refetch())
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function setStateWithReconciliation(res: typeof observerResult) {
|
|
189
|
+
// @ts-expect-error - Reconcile option is not correctly typed internally
|
|
190
|
+
const reconcileOptions = observer().options.reconcile
|
|
191
|
+
|
|
192
|
+
setState((store) => {
|
|
193
|
+
return reconcileFn(
|
|
194
|
+
store,
|
|
195
|
+
res,
|
|
196
|
+
reconcileOptions === undefined ? false : reconcileOptions,
|
|
197
|
+
)
|
|
210
198
|
})
|
|
211
199
|
}
|
|
212
200
|
|
|
201
|
+
function createDeepSignal<T>(): Signal<T> {
|
|
202
|
+
return [
|
|
203
|
+
() => state,
|
|
204
|
+
(v: T) => {
|
|
205
|
+
const unwrapped = unwrap(state)
|
|
206
|
+
if (typeof v === 'function') {
|
|
207
|
+
v = v(unwrapped)
|
|
208
|
+
}
|
|
209
|
+
setStateWithReconciliation(v as any)
|
|
210
|
+
},
|
|
211
|
+
] as Signal<T>
|
|
212
|
+
}
|
|
213
|
+
|
|
213
214
|
/**
|
|
214
215
|
* Unsubscribe is set lazily, so that we can subscribe after hydration when needed.
|
|
215
216
|
*/
|
|
216
217
|
let unsubscribe: (() => void) | null = null
|
|
217
218
|
|
|
218
|
-
const [queryResource, { refetch
|
|
219
|
-
ResourceData | undefined
|
|
220
|
-
>(
|
|
219
|
+
const [queryResource, { refetch }] = createResource<ResourceData | undefined>(
|
|
221
220
|
() => {
|
|
222
221
|
const obs = observer()
|
|
223
222
|
return new Promise((resolve, reject) => {
|
|
@@ -228,19 +227,16 @@ export function createBaseQuery<
|
|
|
228
227
|
}
|
|
229
228
|
obs.updateResult()
|
|
230
229
|
|
|
231
|
-
if (!
|
|
230
|
+
if (!observerResult.isLoading) {
|
|
232
231
|
const query = obs.getCurrentQuery()
|
|
233
|
-
resolve(hydratableObserverResult(query,
|
|
232
|
+
resolve(hydratableObserverResult(query, observerResult))
|
|
233
|
+
} else {
|
|
234
|
+
setStateWithReconciliation(observerResult)
|
|
234
235
|
}
|
|
235
236
|
})
|
|
236
237
|
},
|
|
237
238
|
{
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// If initialData is provided, we resolve the resource immediately
|
|
241
|
-
get ssrLoadFrom() {
|
|
242
|
-
return options().initialData ? 'initial' : 'server'
|
|
243
|
-
},
|
|
239
|
+
storage: createDeepSignal,
|
|
244
240
|
|
|
245
241
|
get deferStream() {
|
|
246
242
|
return options().deferStream
|
|
@@ -273,7 +269,10 @@ export function createBaseQuery<
|
|
|
273
269
|
* even if `staleTime` is not set.
|
|
274
270
|
*/
|
|
275
271
|
const newOptions = { ...initialOptions }
|
|
276
|
-
if (
|
|
272
|
+
if (
|
|
273
|
+
(initialOptions.staleTime || !initialOptions.initialData) &&
|
|
274
|
+
info.value
|
|
275
|
+
) {
|
|
277
276
|
newOptions.refetchOnMount = false
|
|
278
277
|
}
|
|
279
278
|
// Setting the options as an immutable object to prevent
|
|
@@ -330,7 +329,7 @@ export function createBaseQuery<
|
|
|
330
329
|
[observer, defaultedOptions],
|
|
331
330
|
([obs, opts]) => {
|
|
332
331
|
obs.setOptions(opts)
|
|
333
|
-
|
|
332
|
+
setStateWithReconciliation(obs.getOptimisticResult(opts))
|
|
334
333
|
},
|
|
335
334
|
{ defer: true },
|
|
336
335
|
),
|
|
@@ -361,8 +360,14 @@ export function createBaseQuery<
|
|
|
361
360
|
target: QueryObserverResult<TData, TError>,
|
|
362
361
|
prop: keyof QueryObserverResult<TData, TError>,
|
|
363
362
|
): any {
|
|
364
|
-
|
|
365
|
-
|
|
363
|
+
if (prop === 'data') {
|
|
364
|
+
const opts = observer().options
|
|
365
|
+
if (opts.placeholderData) {
|
|
366
|
+
return queryResource.latest?.data
|
|
367
|
+
}
|
|
368
|
+
return queryResource()?.data
|
|
369
|
+
}
|
|
370
|
+
return Reflect.get(target, prop)
|
|
366
371
|
},
|
|
367
372
|
}
|
|
368
373
|
|
package/src/index.ts
CHANGED
package/src/setBatchUpdatesFn.ts
DELETED