@tanstack/solid-query 5.30.1 → 5.30.2

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 CHANGED
@@ -51,14 +51,30 @@ exports.useIsRestoring = () => solidJs.useContext(IsRestoringContext);
51
51
  exports.IsRestoringProvider = IsRestoringContext.Provider;
52
52
 
53
53
  // src/createBaseQuery.ts
54
- function reconcileFn(store$1, result, reconcileOption) {
54
+ function reconcileFn(store$1, result, reconcileOption, queryHash) {
55
55
  if (reconcileOption === false)
56
56
  return result;
57
57
  if (typeof reconcileOption === "function") {
58
58
  const newData2 = reconcileOption(store$1.data, result.data);
59
59
  return { ...result, data: newData2 };
60
60
  }
61
- const newData = store.reconcile(result.data, { key: reconcileOption })(store$1.data);
61
+ let data = result.data;
62
+ if (store$1.data === void 0) {
63
+ try {
64
+ data = structuredClone(data);
65
+ } catch (error) {
66
+ {
67
+ if (error instanceof Error) {
68
+ console.warn(
69
+ `Unable to correctly reconcile data for query key: ${queryHash}. Possibly because the query data contains data structures that aren't supported by the 'structuredClone' algorithm. Consider using a callback function instead to manage the reconciliation manually.
70
+
71
+ Error Received: ${error.name} - ${error.message}`
72
+ );
73
+ }
74
+ }
75
+ }
76
+ }
77
+ const newData = store.reconcile(data, { key: reconcileOption })(store$1.data);
62
78
  return { ...result, data: newData };
63
79
  }
64
80
  var hydratableObserverResult = (query, result) => {
@@ -133,12 +149,14 @@ function createBaseQuery(options, Observer, queryClient) {
133
149
  });
134
150
  };
135
151
  function setStateWithReconciliation(res) {
136
- const reconcileOptions = observer().options.reconcile;
152
+ const opts = observer().options;
153
+ const reconcileOptions = opts.reconcile;
137
154
  setState((store) => {
138
155
  return reconcileFn(
139
156
  store,
140
157
  res,
141
- reconcileOptions === void 0 ? false : reconcileOptions
158
+ reconcileOptions === void 0 ? false : reconcileOptions,
159
+ opts.queryHash
142
160
  );
143
161
  });
144
162
  }
@@ -211,7 +229,7 @@ function createBaseQuery(options, Observer, queryClient) {
211
229
  newOptions.refetchOnMount = false;
212
230
  }
213
231
  observer().setOptions(newOptions);
214
- setState(observer().getOptimisticResult(newOptions));
232
+ setStateWithReconciliation(observer().getOptimisticResult(newOptions));
215
233
  unsubscribe = createClientSubscriber();
216
234
  }
217
235
  }
@@ -266,8 +284,7 @@ function createBaseQuery(options, Observer, queryClient) {
266
284
  const handler = {
267
285
  get(target, prop) {
268
286
  if (prop === "data") {
269
- const opts = observer().options;
270
- if (opts.placeholderData) {
287
+ if (state.data !== void 0) {
271
288
  return queryResource.latest?.data;
272
289
  }
273
290
  return queryResource()?.data;
package/build/dev.js CHANGED
@@ -50,14 +50,30 @@ var useIsRestoring = () => useContext(IsRestoringContext);
50
50
  var IsRestoringProvider = IsRestoringContext.Provider;
51
51
 
52
52
  // src/createBaseQuery.ts
53
- function reconcileFn(store, result, reconcileOption) {
53
+ function reconcileFn(store, result, reconcileOption, queryHash) {
54
54
  if (reconcileOption === false)
55
55
  return result;
56
56
  if (typeof reconcileOption === "function") {
57
57
  const newData2 = reconcileOption(store.data, result.data);
58
58
  return { ...result, data: newData2 };
59
59
  }
60
- const newData = reconcile(result.data, { key: reconcileOption })(store.data);
60
+ let data = result.data;
61
+ if (store.data === void 0) {
62
+ try {
63
+ data = structuredClone(data);
64
+ } catch (error) {
65
+ {
66
+ if (error instanceof Error) {
67
+ console.warn(
68
+ `Unable to correctly reconcile data for query key: ${queryHash}. Possibly because the query data contains data structures that aren't supported by the 'structuredClone' algorithm. Consider using a callback function instead to manage the reconciliation manually.
69
+
70
+ Error Received: ${error.name} - ${error.message}`
71
+ );
72
+ }
73
+ }
74
+ }
75
+ }
76
+ const newData = reconcile(data, { key: reconcileOption })(store.data);
61
77
  return { ...result, data: newData };
62
78
  }
63
79
  var hydratableObserverResult = (query, result) => {
@@ -132,12 +148,14 @@ function createBaseQuery(options, Observer, queryClient) {
132
148
  });
133
149
  };
134
150
  function setStateWithReconciliation(res) {
135
- const reconcileOptions = observer().options.reconcile;
151
+ const opts = observer().options;
152
+ const reconcileOptions = opts.reconcile;
136
153
  setState((store) => {
137
154
  return reconcileFn(
138
155
  store,
139
156
  res,
140
- reconcileOptions === void 0 ? false : reconcileOptions
157
+ reconcileOptions === void 0 ? false : reconcileOptions,
158
+ opts.queryHash
141
159
  );
142
160
  });
143
161
  }
@@ -210,7 +228,7 @@ function createBaseQuery(options, Observer, queryClient) {
210
228
  newOptions.refetchOnMount = false;
211
229
  }
212
230
  observer().setOptions(newOptions);
213
- setState(observer().getOptimisticResult(newOptions));
231
+ setStateWithReconciliation(observer().getOptimisticResult(newOptions));
214
232
  unsubscribe = createClientSubscriber();
215
233
  }
216
234
  }
@@ -265,8 +283,7 @@ function createBaseQuery(options, Observer, queryClient) {
265
283
  const handler = {
266
284
  get(target, prop) {
267
285
  if (prop === "data") {
268
- const opts = observer().options;
269
- if (opts.placeholderData) {
286
+ if (state.data !== void 0) {
270
287
  return queryResource.latest?.data;
271
288
  }
272
289
  return queryResource()?.data;
package/build/index.cjs CHANGED
@@ -51,14 +51,21 @@ exports.useIsRestoring = () => solidJs.useContext(IsRestoringContext);
51
51
  exports.IsRestoringProvider = IsRestoringContext.Provider;
52
52
 
53
53
  // src/createBaseQuery.ts
54
- function reconcileFn(store$1, result, reconcileOption) {
54
+ function reconcileFn(store$1, result, reconcileOption, queryHash) {
55
55
  if (reconcileOption === false)
56
56
  return result;
57
57
  if (typeof reconcileOption === "function") {
58
58
  const newData2 = reconcileOption(store$1.data, result.data);
59
59
  return { ...result, data: newData2 };
60
60
  }
61
- const newData = store.reconcile(result.data, { key: reconcileOption })(store$1.data);
61
+ let data = result.data;
62
+ if (store$1.data === void 0) {
63
+ try {
64
+ data = structuredClone(data);
65
+ } catch (error) {
66
+ }
67
+ }
68
+ const newData = store.reconcile(data, { key: reconcileOption })(store$1.data);
62
69
  return { ...result, data: newData };
63
70
  }
64
71
  var hydratableObserverResult = (query, result) => {
@@ -133,12 +140,14 @@ function createBaseQuery(options, Observer, queryClient) {
133
140
  });
134
141
  };
135
142
  function setStateWithReconciliation(res) {
136
- const reconcileOptions = observer().options.reconcile;
143
+ const opts = observer().options;
144
+ const reconcileOptions = opts.reconcile;
137
145
  setState((store) => {
138
146
  return reconcileFn(
139
147
  store,
140
148
  res,
141
- reconcileOptions === void 0 ? false : reconcileOptions
149
+ reconcileOptions === void 0 ? false : reconcileOptions,
150
+ opts.queryHash
142
151
  );
143
152
  });
144
153
  }
@@ -211,7 +220,7 @@ function createBaseQuery(options, Observer, queryClient) {
211
220
  newOptions.refetchOnMount = false;
212
221
  }
213
222
  observer().setOptions(newOptions);
214
- setState(observer().getOptimisticResult(newOptions));
223
+ setStateWithReconciliation(observer().getOptimisticResult(newOptions));
215
224
  unsubscribe = createClientSubscriber();
216
225
  }
217
226
  }
@@ -266,8 +275,7 @@ function createBaseQuery(options, Observer, queryClient) {
266
275
  const handler = {
267
276
  get(target, prop) {
268
277
  if (prop === "data") {
269
- const opts = observer().options;
270
- if (opts.placeholderData) {
278
+ if (state.data !== void 0) {
271
279
  return queryResource.latest?.data;
272
280
  }
273
281
  return queryResource()?.data;
package/build/index.js CHANGED
@@ -50,14 +50,21 @@ var useIsRestoring = () => useContext(IsRestoringContext);
50
50
  var IsRestoringProvider = IsRestoringContext.Provider;
51
51
 
52
52
  // src/createBaseQuery.ts
53
- function reconcileFn(store, result, reconcileOption) {
53
+ function reconcileFn(store, result, reconcileOption, queryHash) {
54
54
  if (reconcileOption === false)
55
55
  return result;
56
56
  if (typeof reconcileOption === "function") {
57
57
  const newData2 = reconcileOption(store.data, result.data);
58
58
  return { ...result, data: newData2 };
59
59
  }
60
- const newData = reconcile(result.data, { key: reconcileOption })(store.data);
60
+ let data = result.data;
61
+ if (store.data === void 0) {
62
+ try {
63
+ data = structuredClone(data);
64
+ } catch (error) {
65
+ }
66
+ }
67
+ const newData = reconcile(data, { key: reconcileOption })(store.data);
61
68
  return { ...result, data: newData };
62
69
  }
63
70
  var hydratableObserverResult = (query, result) => {
@@ -132,12 +139,14 @@ function createBaseQuery(options, Observer, queryClient) {
132
139
  });
133
140
  };
134
141
  function setStateWithReconciliation(res) {
135
- const reconcileOptions = observer().options.reconcile;
142
+ const opts = observer().options;
143
+ const reconcileOptions = opts.reconcile;
136
144
  setState((store) => {
137
145
  return reconcileFn(
138
146
  store,
139
147
  res,
140
- reconcileOptions === void 0 ? false : reconcileOptions
148
+ reconcileOptions === void 0 ? false : reconcileOptions,
149
+ opts.queryHash
141
150
  );
142
151
  });
143
152
  }
@@ -210,7 +219,7 @@ function createBaseQuery(options, Observer, queryClient) {
210
219
  newOptions.refetchOnMount = false;
211
220
  }
212
221
  observer().setOptions(newOptions);
213
- setState(observer().getOptimisticResult(newOptions));
222
+ setStateWithReconciliation(observer().getOptimisticResult(newOptions));
214
223
  unsubscribe = createClientSubscriber();
215
224
  }
216
225
  }
@@ -265,8 +274,7 @@ function createBaseQuery(options, Observer, queryClient) {
265
274
  const handler = {
266
275
  get(target, prop) {
267
276
  if (prop === "data") {
268
- const opts = observer().options;
269
- if (opts.placeholderData) {
277
+ if (state.data !== void 0) {
270
278
  return queryResource.latest?.data;
271
279
  }
272
280
  return queryResource()?.data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-query",
3
- "version": "5.30.1",
3
+ "version": "5.30.2",
4
4
  "description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -1051,7 +1051,9 @@ describe('createQuery', () => {
1051
1051
  count++
1052
1052
  return count === 1 ? result1 : result2
1053
1053
  },
1054
- reconcile: 'id',
1054
+ reconcile: (oldData, newData) => {
1055
+ return reconcile(newData)(oldData)
1056
+ },
1055
1057
  }))
1056
1058
 
1057
1059
  createRenderEffect(() => {
@@ -34,13 +34,31 @@ function reconcileFn<TData, TError>(
34
34
  | string
35
35
  | false
36
36
  | ((oldData: TData | undefined, newData: TData) => TData),
37
+ queryHash?: string,
37
38
  ): QueryObserverResult<TData, TError> {
38
39
  if (reconcileOption === false) return result
39
40
  if (typeof reconcileOption === 'function') {
40
41
  const newData = reconcileOption(store.data, result.data as TData)
41
42
  return { ...result, data: newData } as typeof result
42
43
  }
43
- const newData = reconcile(result.data, { key: reconcileOption })(store.data)
44
+ let data = result.data
45
+ if (store.data === undefined) {
46
+ try {
47
+ data = structuredClone(data)
48
+ } catch (error) {
49
+ if (process.env.NODE_ENV !== 'production') {
50
+ if (error instanceof Error) {
51
+ console.warn(
52
+ `Unable to correctly reconcile data for query key: ${queryHash}. ` +
53
+ `Possibly because the query data contains data structures that aren't supported ` +
54
+ `by the 'structuredClone' algorithm. Consider using a callback function instead ` +
55
+ `to manage the reconciliation manually.\n\n Error Received: ${error.name} - ${error.message}`,
56
+ )
57
+ }
58
+ }
59
+ }
60
+ }
61
+ const newData = reconcile(data, { key: reconcileOption })(store.data)
44
62
  return { ...result, data: newData } as typeof result
45
63
  }
46
64
 
@@ -186,14 +204,16 @@ export function createBaseQuery<
186
204
  }
187
205
 
188
206
  function setStateWithReconciliation(res: typeof observerResult) {
207
+ const opts = observer().options
189
208
  // @ts-expect-error - Reconcile option is not correctly typed internally
190
- const reconcileOptions = observer().options.reconcile
209
+ const reconcileOptions = opts.reconcile
191
210
 
192
211
  setState((store) => {
193
212
  return reconcileFn(
194
213
  store,
195
214
  res,
196
215
  reconcileOptions === undefined ? false : reconcileOptions,
216
+ opts.queryHash,
197
217
  )
198
218
  })
199
219
  }
@@ -290,7 +310,7 @@ export function createBaseQuery<
290
310
  // Setting the options as an immutable object to prevent
291
311
  // wonky behavior with observer subscriptions
292
312
  observer().setOptions(newOptions)
293
- setState(observer().getOptimisticResult(newOptions))
313
+ setStateWithReconciliation(observer().getOptimisticResult(newOptions))
294
314
  unsubscribe = createClientSubscriber()
295
315
  },
296
316
  },
@@ -353,8 +373,7 @@ export function createBaseQuery<
353
373
  prop: keyof QueryObserverResult<TData, TError>,
354
374
  ): any {
355
375
  if (prop === 'data') {
356
- const opts = observer().options
357
- if (opts.placeholderData) {
376
+ if (state.data !== undefined) {
358
377
  return queryResource.latest?.data
359
378
  }
360
379
  return queryResource()?.data