@tanstack/solid-query 5.103.1 → 5.103.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-query",
3
- "version": "5.103.1",
3
+ "version": "5.103.3",
4
4
  "description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -46,15 +46,15 @@
46
46
  "!src/__tests__"
47
47
  ],
48
48
  "dependencies": {
49
- "@tanstack/query-core": "5.103.1"
49
+ "@tanstack/query-core": "5.103.3"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@solidjs/testing-library": "^0.8.10",
53
- "npm-run-all2": "^5.0.0",
54
- "solid-js": "^1.9.7",
53
+ "@tanstack/query-test-utils": "0.0.0",
54
+ "npm-run-all2": "^9.0.3",
55
+ "solid-js": "^1.9.15",
55
56
  "unplugin-solid": "^2.0.0",
56
- "vite-plugin-solid": "^2.11.6",
57
- "@tanstack/query-test-utils": "0.0.0"
57
+ "vite-plugin-solid": "^2.11.14"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "solid-js": "^1.6.0"
@@ -45,9 +45,7 @@ export interface QueryObserverOptions<
45
45
  * Defaults reconciliation to false.
46
46
  */
47
47
  reconcile?:
48
- | string
49
- | false
50
- | ((oldData: TData | undefined, newData: TData) => TData)
48
+ string | false | ((oldData: TData | undefined, newData: TData) => TData)
51
49
  }
52
50
 
53
51
  /**
@@ -82,9 +80,7 @@ export interface InfiniteQueryObserverOptions<
82
80
  * Defaults reconciliation to false.
83
81
  */
84
82
  reconcile?:
85
- | string
86
- | false
87
- | ((oldData: TData | undefined, newData: TData) => TData)
83
+ string | false | ((oldData: TData | undefined, newData: TData) => TData)
88
84
  }
89
85
 
90
86
  /**
@@ -18,7 +18,7 @@ const queryClientContextError =
18
18
  'No QueryClient set, use QueryClientProvider to set one'
19
19
 
20
20
  /**
21
- * The `useQueryClient` hook returns the current `QueryClient` instance.
21
+ * The `useQueryClient` primitive returns the current `QueryClient` instance.
22
22
  *
23
23
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
24
24
  * be used.
@@ -36,7 +36,7 @@ export type UndefinedInitialDataInfiniteOptions<
36
36
 
37
37
  /**
38
38
  * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
39
- * never `undefined`.
39
+ * never `undefined` (unless a `select` changes `TData` to include `undefined`).
40
40
  *
41
41
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
42
42
  * @template TError - The type of errors your `queryFn` may throw.
@@ -4,7 +4,7 @@ import type { Accessor } from 'solid-js'
4
4
  const IsRestoringContext = createContext<Accessor<boolean>>(() => false)
5
5
 
6
6
  /**
7
- * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
7
+ * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` primitive alongside it to
8
8
  * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
9
9
  * race conditions between the restore and mounting queries.
10
10
  *
@@ -30,7 +30,7 @@ export type UndefinedInitialDataOptions<
30
30
 
31
31
  /**
32
32
  * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
33
- * `undefined`.
33
+ * `undefined` (unless a `select` changes `TData` to include `undefined`).
34
34
  *
35
35
  * @template TQueryFnData - The type your `queryFn` resolves to.
36
36
  * @template TError - The type of errors your `queryFn` may throw.
@@ -53,7 +53,8 @@ export type DefinedInitialDataOptions<
53
53
  * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
54
54
  * is the query key to generate options for.
55
55
  *
56
- * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
56
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
57
+ * a `select` changes `TData` to include `undefined`).
57
58
  *
58
59
  * @see {@link useQuery} to run a query with these options.
59
60
  * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
package/src/types.ts CHANGED
@@ -45,7 +45,8 @@ export interface UseBaseQueryOptions<
45
45
  * Only applicable while rendering queries on the server with streaming.
46
46
  * Set `deferStream` to `true` to wait for the query to resolve on the server before flushing the stream.
47
47
  * This can be useful to avoid sending a loading state to the client before the query has resolved.
48
- * Defaults to `false`.
48
+ *
49
+ * @defaultValue false
49
50
  */
50
51
  deferStream?: boolean
51
52
  /**
@@ -123,7 +124,8 @@ export type UseQueryResult<
123
124
  > = UseBaseQueryResult<TData, TError>
124
125
 
125
126
  /**
126
- * 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`).
127
129
  *
128
130
  * @template TData - The type `data` ends up as, after `select` runs (if set).
129
131
  * @template TError - The type of errors this query may hold.
@@ -134,7 +136,8 @@ export type DefinedUseBaseQueryResult<
134
136
  > = DefinedQueryObserverResult<TData, TError>
135
137
 
136
138
  /**
137
- * 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`).
138
141
  *
139
142
  * @template TData - The type `data` ends up as, after `select` runs (if set).
140
143
  * @template TError - The type of errors this query may hold.
@@ -170,12 +173,21 @@ export interface InfiniteQueryOptions<
170
173
  >,
171
174
  'queryKey' | 'suspense'
172
175
  > {
176
+ /**
177
+ * The query key to use for this query. Required here, unlike on the options this type extends.
178
+ *
179
+ * The query key will be hashed into a stable hash. See [Query Keys](https://tanstack.com/query/latest/docs/framework/solid/guides/query-keys)
180
+ * for more information.
181
+ *
182
+ * The query will automatically update when this key changes (as long as `enabled` is not set to `false`).
183
+ */
173
184
  queryKey: TQueryKey
174
185
  /**
175
186
  * Only applicable while rendering queries on the server with streaming.
176
187
  * Set `deferStream` to `true` to wait for the query to resolve on the server before flushing the stream.
177
188
  * This can be useful to avoid sending a loading state to the client before the query has resolved.
178
- * Defaults to `false`.
189
+ *
190
+ * @defaultValue false
179
191
  */
180
192
  deferStream?: boolean
181
193
  /**
@@ -219,7 +231,8 @@ export type UseInfiniteQueryResult<
219
231
  > = InfiniteQueryObserverResult<TData, TError>
220
232
 
221
233
  /**
222
- * 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`).
223
236
  *
224
237
  * @template TData - The type `data` ends up as, after `select` runs (if set).
225
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
  }
@@ -5,7 +5,7 @@ import type { QueryClient } from './QueryClient'
5
5
  import type { Accessor } from 'solid-js'
6
6
 
7
7
  /**
8
- * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching
8
+ * The `useIsFetching` primitive returns the `number` of the queries that your application is loading or fetching
9
9
  * in the background (useful for app-wide loading indicators).
10
10
  *
11
11
  * @param filters - An accessor returning the {@link QueryFilters} to narrow down the matched queries.
@@ -5,7 +5,7 @@ import type { QueryClient } from './QueryClient'
5
5
  import type { Accessor } from 'solid-js'
6
6
 
7
7
  /**
8
- * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
8
+ * The `useIsMutating` primitive returns the `number` of mutations that your application currently has `pending`
9
9
  * (useful for app-wide loading indicators).
10
10
  *
11
11
  * @param filters - An accessor returning the {@link MutationFilters} to narrow down the matched mutations.
@@ -12,6 +12,9 @@ import type {
12
12
  import type { Accessor } from 'solid-js'
13
13
 
14
14
  /**
15
+ * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
16
+ * `useMutation` is the primitive for that.
17
+ *
15
18
  * @param options - An accessor returning the {@link UseMutationOptions} to use.
16
19
  * @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
17
20
  * will be used.
@@ -49,7 +49,7 @@ function getResult<
49
49
  }
50
50
 
51
51
  /**
52
- * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
52
+ * `useMutationState` is a primitive that gives you access to all mutations in the `MutationCache`. You can pass
53
53
  * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation
54
54
  * state.
55
55
  *
package/src/useQueries.ts CHANGED
@@ -185,7 +185,7 @@ type QueriesResults<
185
185
  : { [K in keyof T]: GetResults<T[K]> }
186
186
 
187
187
  /**
188
- * The `useQueries` hook can be used to fetch a variable number of queries.
188
+ * The `useQueries` primitive can be used to fetch a variable number of queries.
189
189
  *
190
190
  * The `queries` key accepts an array with query option objects mostly identical to `useQuery` — see
191
191
  * `placeholderData` below for the one difference. A custom `QueryClient` is supplied once, as `useQueries`'
package/src/useQuery.ts CHANGED
@@ -15,6 +15,9 @@ import type {
15
15
  } from './queryOptions'
16
16
 
17
17
  /**
18
+ * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
19
+ * The query runs when the options call for it — `enabled: false` skips the initial fetch.
20
+ *
18
21
  * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
19
22
  * @param options - An accessor returning the {@link UndefinedInitialDataOptions} to use — everything you can
20
23
  * pass to `useQuery`.
@@ -124,7 +127,9 @@ import type {
124
127
  * ```
125
128
  *
126
129
  * @example
127
- * 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:
128
133
  * ```tsx
129
134
  * import { useQuery, useQueryClient } from '@tanstack/solid-query'
130
135
  *
@@ -138,6 +143,8 @@ import type {
138
143
  * queryClient
139
144
  * .getQueryData<Array<Post>>(['posts'])
140
145
  * ?.find((post) => post.id === props.postId),
146
+ * initialDataUpdatedAt: () =>
147
+ * queryClient.getQueryState(['posts'])?.dataUpdatedAt,
141
148
  * }))
142
149
  *
143
150
  * return postQuery.isError ? <span>Error: {postQuery.error.message}</span> : <h1>{postQuery.data?.title}</h1>
@@ -186,7 +193,11 @@ export function useQuery<
186
193
  ): UseQueryResult<TData, TError>
187
194
 
188
195
  /**
189
- * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
196
+ * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
197
+ * The query runs when the options call for it — `enabled: false` skips the initial fetch.
198
+ *
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`).
190
201
  *
191
202
  * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
192
203
  * @param options - An accessor returning the {@link DefinedInitialDataOptions} to use — everything you can