Skip to content

Commit 1ef4208

Browse files
authored
ref: remove experimental_prefetchInRender (#11221)
1 parent bf7ae20 commit 1ef4208

36 files changed

Lines changed: 63 additions & 2274 deletions

.changeset/quiet-flags-remove.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@tanstack/angular-query-experimental': patch
3+
'@tanstack/lit-query': patch
4+
'@tanstack/preact-query': patch
5+
'@tanstack/query-core': patch
6+
'@tanstack/react-query': patch
7+
'@tanstack/solid-query': patch
8+
'@tanstack/svelte-query': patch
9+
'@tanstack/vue-query': patch
10+
---
11+
12+
Remove experimental render-time prefetching and the `promise` property from query results.

docs/framework/react/guides/suspense.md

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ React Query can also be used with React's Suspense for Data Fetching APIs. For t
88
- [useSuspenseQuery](../reference/useSuspenseQuery.md)
99
- [useSuspenseInfiniteQuery](../reference/useSuspenseInfiniteQuery.md)
1010
- [useSuspenseQueries](../reference/useSuspenseQueries.md)
11-
- Additionally, you can use the `useQuery().promise` and `React.use()` (Experimental)
1211

1312
When using suspense mode, `status` states and `error` objects are not needed and are then replaced by usage of the `React.Suspense` component (including the use of the `fallback` prop and React error boundaries for catching errors). Please read the [Resetting Error Boundaries](#resetting-error-boundaries) and look at the [Suspense Example](../examples/suspense) for more information on how to set up suspense mode.
1413

@@ -173,56 +172,3 @@ export function Providers(props: { children: React.ReactNode }) {
173172
```
174173

175174
For more information, check out the [NextJs Suspense Streaming Example](../examples/nextjs-suspense-streaming) and the [Advanced Rendering & Hydration](./advanced-ssr.md) guide.
176-
177-
## Using `useQuery().promise` and `React.use()` (Experimental)
178-
179-
> To enable this feature, you need to set the `experimental_prefetchInRender` option to `true` when creating your `QueryClient`
180-
181-
**Example code:**
182-
183-
```tsx
184-
const queryClient = new QueryClient({
185-
defaultOptions: {
186-
queries: {
187-
experimental_prefetchInRender: true,
188-
},
189-
},
190-
})
191-
```
192-
193-
**Usage:**
194-
195-
```tsx
196-
import React from 'react'
197-
import { useQuery } from '@tanstack/react-query'
198-
import { fetchTodos, type Todo } from './api'
199-
200-
function TodoList({ query }: { query: UseQueryResult<Todo[]> }) {
201-
const data = React.use(query.promise)
202-
203-
return (
204-
<ul>
205-
{data.map((todo) => (
206-
<li key={todo.id}>{todo.title}</li>
207-
))}
208-
</ul>
209-
)
210-
}
211-
212-
export function App() {
213-
const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })
214-
215-
return (
216-
<>
217-
<h1>Todos</h1>
218-
<React.Suspense fallback={<div>Loading...</div>}>
219-
<TodoList query={query} />
220-
</React.Suspense>
221-
</>
222-
)
223-
}
224-
```
225-
226-
For a more complete example, see [suspense example on GitHub](https://github.com/TanStack/query/tree/main/examples/react/suspense).
227-
228-
For a Next.js streaming example, see [nextjs-suspense-streaming example on GitHub](https://github.com/TanStack/query/tree/main/examples/react/nextjs-suspense-streaming).

docs/framework/react/reference/queryOptions.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ You can generally pass everything to `queryOptions` that you can also pass to [`
1717
- `queryKey: QueryKey`
1818
- **Required**
1919
- The query key to generate options for.
20-
- `experimental_prefetchInRender?: boolean`
21-
- Optional
22-
- Defaults to `false`
23-
- When set to `true`, queries will be prefetched during render, which can be useful for certain optimization scenarios
24-
- Needs to be turned on for the experimental `useQuery().promise` functionality
25-
2620
[//]: # 'Materials'
2721

2822
## Further reading

docs/framework/react/reference/useInfiniteQuery.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const {
1111
hasPreviousPage,
1212
isFetchingNextPage,
1313
isFetchingPreviousPage,
14-
promise,
1514
...result
1615
} = useInfiniteQuery({
1716
queryKey,
@@ -86,11 +85,4 @@ The returned properties for `useInfiniteQuery` are identical to the [`useQuery`
8685
- Is the same as `isFetching && !isPending && !isFetchingNextPage && !isFetchingPreviousPage`
8786
- `isRefetchError: boolean`
8887
- Will be `true` if the query failed while refetching a page.
89-
- `promise: Promise<TData>`
90-
- A stable promise that resolves to the query result.
91-
[//]: # 'ReactUse'
92-
- This can be used with `React.use()` to fetch data
93-
[//]: # 'ReactUse'
94-
- Requires the `experimental_prefetchInRender` feature flag to be enabled on the `QueryClient`.
95-
9688
Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default refetch behaviour, resulting in outdated data. Make sure to call these functions only in response to user actions, or add conditions like `hasNextPage && !isFetching`.

docs/framework/react/reference/useQuery.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const {
2828
isStale,
2929
isSuccess,
3030
isEnabled,
31-
promise,
3231
refetch,
3332
status,
3433
} = useQuery(
@@ -257,6 +256,3 @@ const {
257256
- Defaults to `true`
258257
- Per default, a currently running request will be cancelled before a new request is made
259258
- When set to `false`, no refetch will be made if there is already a request running.
260-
- `promise: Promise<TData>`
261-
- A stable promise that will be resolved with the data of the query.
262-
- Requires the `experimental_prefetchInRender` feature flag to be enabled on the `QueryClient`.

packages/lit-query/src/createInfiniteQueryController.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ function createPendingInfiniteQueryResult<
109109
isFetchingNextPage: false,
110110
isFetchPreviousPageError: false,
111111
isFetchingPreviousPage: false,
112-
promise: Promise.resolve(undefined as never),
113112
} as unknown as InfiniteQueryObserverResult<TData, TError>
114113
}
115114

packages/lit-query/src/createQueriesController.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ function createPendingQueryObserverResult(): QueryObserverResult {
251251
Promise.reject(
252252
createMissingQueryClientError(),
253253
)) as QueryObserverResult['refetch'],
254-
promise: Promise.resolve(undefined as never),
255254
} as unknown as QueryObserverResult
256255
}
257256

@@ -282,7 +281,6 @@ function createPlaceholderQueryObserverResult(
282281
isLoading: false,
283282
isSuccess: true,
284283
status: 'success',
285-
promise: Promise.resolve(data as never),
286284
} as QueryObserverResult
287285
}
288286

packages/lit-query/src/createQueryController.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ function createPendingQueryResult<TData, TError>(): QueryObserverResult<
8484
TData,
8585
TError
8686
>['refetch'],
87-
promise: Promise.resolve(undefined as never),
8887
} as unknown as QueryObserverResult<TData, TError>
8988
}
9089

packages/preact-query/src/__tests__/useInfiniteQuery.test.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ describe('useInfiniteQuery', () => {
3838
queryCache = new QueryCache()
3939
queryClient = new QueryClient({
4040
queryCache,
41-
defaultOptions: {
42-
queries: {
43-
experimental_prefetchInRender: true,
44-
},
45-
},
4641
})
4742
})
4843

@@ -105,7 +100,6 @@ describe('useInfiniteQuery', () => {
105100
refetch: expect.any(Function),
106101
status: 'pending',
107102
fetchStatus: 'fetching',
108-
promise: expect.any(Promise),
109103
})
110104
expect(states[1]).toEqual({
111105
data: { pages: [0], pageParams: [0] },
@@ -141,7 +135,6 @@ describe('useInfiniteQuery', () => {
141135
refetch: expect.any(Function),
142136
status: 'success',
143137
fetchStatus: 'idle',
144-
promise: expect.any(Promise),
145138
})
146139
})
147140

packages/preact-query/src/__tests__/useQuery.test-d.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('useQuery', () => {
1717
const fromQueryFn = useQuery({ queryKey: key, queryFn: () => 'test' })
1818
expectTypeOf(fromQueryFn.data).toEqualTypeOf<string | undefined>()
1919
expectTypeOf(fromQueryFn.error).toEqualTypeOf<Error | null>()
20-
expectTypeOf(fromQueryFn.promise).toEqualTypeOf<Promise<string>>()
20+
expectTypeOf(fromQueryFn).not.toHaveProperty('promise')
2121

2222
// it should be possible to specify the result type
2323
const withResult = useQuery<string>({

0 commit comments

Comments
 (0)