@tanstack/solid-query 5.103.2 → 5.104.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/src/types.ts CHANGED
@@ -124,7 +124,8 @@ export type UseQueryResult<
124
124
  > = UseBaseQueryResult<TData, TError>
125
125
 
126
126
  /**
127
- * The object `useQuery` returns when `initialData` guarantees `data` is never `undefined`.
127
+ * The object `useQuery` returns when `initialData` guarantees `data` is never `undefined` (unless a
128
+ * `select` changes `TData` to include `undefined`).
128
129
  *
129
130
  * @template TData - The type `data` ends up as, after `select` runs (if set).
130
131
  * @template TError - The type of errors this query may hold.
@@ -135,7 +136,8 @@ export type DefinedUseBaseQueryResult<
135
136
  > = DefinedQueryObserverResult<TData, TError>
136
137
 
137
138
  /**
138
- * The object `useQuery` returns when `initialData` guarantees `data` is never `undefined`.
139
+ * The object `useQuery` returns when `initialData` guarantees `data` is never `undefined` (unless a
140
+ * `select` changes `TData` to include `undefined`).
139
141
  *
140
142
  * @template TData - The type `data` ends up as, after `select` runs (if set).
141
143
  * @template TError - The type of errors this query may hold.
@@ -229,7 +231,8 @@ export type UseInfiniteQueryResult<
229
231
  > = InfiniteQueryObserverResult<TData, TError>
230
232
 
231
233
  /**
232
- * The object `useInfiniteQuery` returns when `initialData` guarantees `data` is never `undefined`.
234
+ * The object `useInfiniteQuery` returns when `initialData` guarantees `data` is never `undefined` (unless a
235
+ * `select` changes `TData` to include `undefined`).
233
236
  *
234
237
  * @template TData - The type `data` ends up as, after `select` runs (if set).
235
238
  * @template TError - The type of errors this query may hold.
@@ -28,9 +28,7 @@ function reconcileFn<TData, TError>(
28
28
  store: QueryObserverResult<TData, TError>,
29
29
  result: QueryObserverResult<TData, TError>,
30
30
  reconcileOption:
31
- | string
32
- | false
33
- | ((oldData: TData | undefined, newData: TData) => TData),
31
+ string | false | ((oldData: TData | undefined, newData: TData) => TData),
34
32
  queryHash?: string,
35
33
  ): QueryObserverResult<TData, TError> {
36
34
  if (reconcileOption === false) return result
@@ -342,7 +340,7 @@ export function useBaseQuery<
342
340
  )
343
341
 
344
342
  onCleanup(() => {
345
- if (isServer && queryResource.loading) {
343
+ if (isServer && queryResource.state === 'pending') {
346
344
  unsubscribeQueued = true
347
345
  return
348
346
  }
package/src/useQuery.ts CHANGED
@@ -127,7 +127,9 @@ import type {
127
127
  * ```
128
128
  *
129
129
  * @example
130
- * Seeding a detail query from an already-cached list, to skip the loading state:
130
+ * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries
131
+ * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was
132
+ * fetched rather than from now:
131
133
  * ```tsx
132
134
  * import { useQuery, useQueryClient } from '@tanstack/solid-query'
133
135
  *
@@ -141,6 +143,8 @@ import type {
141
143
  * queryClient
142
144
  * .getQueryData<Array<Post>>(['posts'])
143
145
  * ?.find((post) => post.id === props.postId),
146
+ * initialDataUpdatedAt: () =>
147
+ * queryClient.getQueryState(['posts'])?.dataUpdatedAt,
144
148
  * }))
145
149
  *
146
150
  * return postQuery.isError ? <span>Error: {postQuery.error.message}</span> : <h1>{postQuery.data?.title}</h1>
@@ -192,7 +196,8 @@ export function useQuery<
192
196
  * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
193
197
  * The query runs when the options call for it — `enabled: false` skips the initial fetch.
194
198
  *
195
- * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
199
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
200
+ * a `select` changes `TData` to include `undefined`).
196
201
  *
197
202
  * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
198
203
  * @param options - An accessor returning the {@link DefinedInitialDataOptions} to use — everything you can