From 6aaa488abbe2b215088bf063d7e296bb70c4e4c9 Mon Sep 17 00:00:00 2001 From: TkDodo Date: Sun, 22 Nov 2026 15:03:02 +0100 Subject: [PATCH] feat(query-core)!: stabilize streamedQuery for v6 --- .changeset/stable-streamed-query.md | 5 ++ docs/config.json | 56 +++++++++---------- docs/framework/vue/guides/suspense.md | 2 +- examples/lit/chat/README.md | 2 +- .../lit/chat/src/services/messages/queries.ts | 5 +- examples/preact/chat/README.md | 2 +- .../chat/src/services/messages/queries.ts | 5 +- examples/react/chat/README.md | 2 +- .../chat/src/services/messages/queries.ts | 5 +- examples/solid/chat/README.md | 2 +- .../chat/src/services/messages/queries.ts | 5 +- examples/svelte/chat/README.md | 2 +- .../chat/src/lib/services/messages/queries.ts | 5 +- examples/vue/chat/README.md | 2 +- .../vue/chat/src/services/messages/queries.ts | 5 +- .../src/__tests__/useSuspenseQuery.test.tsx | 4 +- .../src/__tests__/streamedQuery.test-d.tsx | 2 +- .../src/__tests__/streamedQuery.test.tsx | 3 +- packages/query-core/src/index.ts | 2 +- packages/query-core/src/streamedQuery.ts | 21 +++---- .../src/__tests__/useSuspenseQuery.test.tsx | 4 +- .../vue-query/src/__tests__/useQuery.test.ts | 4 +- scripts/generate-docs.ts | 35 +++++++++++- 23 files changed, 98 insertions(+), 82 deletions(-) create mode 100644 .changeset/stable-streamed-query.md diff --git a/.changeset/stable-streamed-query.md b/.changeset/stable-streamed-query.md new file mode 100644 index 00000000000..75099a30640 --- /dev/null +++ b/.changeset/stable-streamed-query.md @@ -0,0 +1,5 @@ +--- +'@tanstack/query-core': major +--- + +Stabilize `streamedQuery`. Replace imports of `experimental_streamedQuery` with `streamedQuery` in v6. diff --git a/docs/config.json b/docs/config.json index 005732b541c..225ab41cb30 100644 --- a/docs/config.json +++ b/docs/config.json @@ -1068,10 +1068,6 @@ "label": "Functions / dehydrateQuery", "to": "framework/react/reference/functions/dehydrateQuery" }, - { - "label": "Functions / experimental_streamedQuery", - "to": "framework/react/reference/functions/experimental_streamedQuery" - }, { "label": "Functions / hashKey", "to": "framework/react/reference/functions/hashKey" @@ -1124,6 +1120,10 @@ "label": "Functions / shouldThrowError", "to": "framework/react/reference/functions/shouldThrowError" }, + { + "label": "Functions / streamedQuery", + "to": "framework/react/reference/functions/streamedQuery" + }, { "label": "Functions / useInfiniteQuery", "to": "framework/react/reference/functions/useInfiniteQuery" @@ -1937,10 +1937,6 @@ "label": "Functions / dehydrateQuery", "to": "framework/vue/reference/functions/dehydrateQuery" }, - { - "label": "Functions / experimental_streamedQuery", - "to": "framework/vue/reference/functions/experimental_streamedQuery" - }, { "label": "Functions / hashKey", "to": "framework/vue/reference/functions/hashKey" @@ -1993,6 +1989,10 @@ "label": "Functions / shouldThrowError", "to": "framework/vue/reference/functions/shouldThrowError" }, + { + "label": "Functions / streamedQuery", + "to": "framework/vue/reference/functions/streamedQuery" + }, { "label": "Functions / useInfiniteQuery", "to": "framework/vue/reference/functions/useInfiniteQuery" @@ -2694,10 +2694,6 @@ "label": "Functions / dehydrateQuery", "to": "framework/solid/reference/functions/dehydrateQuery" }, - { - "label": "Functions / experimental_streamedQuery", - "to": "framework/solid/reference/functions/experimental_streamedQuery" - }, { "label": "Functions / hashKey", "to": "framework/solid/reference/functions/hashKey" @@ -2750,6 +2746,10 @@ "label": "Functions / shouldThrowError", "to": "framework/solid/reference/functions/shouldThrowError" }, + { + "label": "Functions / streamedQuery", + "to": "framework/solid/reference/functions/streamedQuery" + }, { "label": "Functions / useInfiniteQuery", "to": "framework/solid/reference/functions/useInfiniteQuery" @@ -3483,10 +3483,6 @@ "label": "Functions / dehydrateQuery", "to": "framework/svelte/reference/functions/dehydrateQuery" }, - { - "label": "Functions / experimental_streamedQuery", - "to": "framework/svelte/reference/functions/experimental_streamedQuery" - }, { "label": "Functions / getIsRestoringContext", "to": "framework/svelte/reference/functions/getIsRestoringContext" @@ -3555,6 +3551,10 @@ "label": "Functions / shouldThrowError", "to": "framework/svelte/reference/functions/shouldThrowError" }, + { + "label": "Functions / streamedQuery", + "to": "framework/svelte/reference/functions/streamedQuery" + }, { "label": "Functions / useHydrate", "to": "framework/svelte/reference/functions/useHydrate" @@ -4300,10 +4300,6 @@ "label": "Functions / dehydrateQuery", "to": "framework/lit/reference/functions/dehydrateQuery" }, - { - "label": "Functions / experimental_streamedQuery", - "to": "framework/lit/reference/functions/experimental_streamedQuery" - }, { "label": "Functions / hashKey", "to": "framework/lit/reference/functions/hashKey" @@ -4356,6 +4352,10 @@ "label": "Functions / shouldThrowError", "to": "framework/lit/reference/functions/shouldThrowError" }, + { + "label": "Functions / streamedQuery", + "to": "framework/lit/reference/functions/streamedQuery" + }, { "label": "Functions / useIsFetching", "to": "framework/lit/reference/functions/useIsFetching" @@ -5025,10 +5025,6 @@ "label": "Functions / dehydrateQuery", "to": "framework/angular/reference/functions/dehydrateQuery" }, - { - "label": "Functions / experimental_streamedQuery", - "to": "framework/angular/reference/functions/experimental_streamedQuery" - }, { "label": "Functions / hashKey", "to": "framework/angular/reference/functions/hashKey" @@ -5117,6 +5113,10 @@ "label": "Functions / shouldThrowError", "to": "framework/angular/reference/functions/shouldThrowError" }, + { + "label": "Functions / streamedQuery", + "to": "framework/angular/reference/functions/streamedQuery" + }, { "label": "Functions / toResource", "to": "framework/angular/reference/functions/toResource" @@ -5834,10 +5834,6 @@ "label": "Functions / dehydrateQuery", "to": "framework/preact/reference/functions/dehydrateQuery" }, - { - "label": "Functions / experimental_streamedQuery", - "to": "framework/preact/reference/functions/experimental_streamedQuery" - }, { "label": "Functions / hashKey", "to": "framework/preact/reference/functions/hashKey" @@ -5890,6 +5886,10 @@ "label": "Functions / shouldThrowError", "to": "framework/preact/reference/functions/shouldThrowError" }, + { + "label": "Functions / streamedQuery", + "to": "framework/preact/reference/functions/streamedQuery" + }, { "label": "Functions / useInfiniteQuery", "to": "framework/preact/reference/functions/useInfiniteQuery" diff --git a/docs/framework/vue/guides/suspense.md b/docs/framework/vue/guides/suspense.md index af8825a96af..604ed27701b 100644 --- a/docs/framework/vue/guides/suspense.md +++ b/docs/framework/vue/guides/suspense.md @@ -54,7 +54,7 @@ export default defineComponent({ ## How `suspense()` resolves -- If the query has no data or its data is stale, it fetches the query and resolves with the result once that fetch resolves. This is usually when the query function finishes, but can be earlier, such as after the first chunk of an `experimental_streamedQuery` or when `setQueryData` sets data while the fetch is in flight. +- If the query has no data or its data is stale, it fetches the query and resolves with the result once that fetch resolves. This is usually when the query function finishes, but can be earlier, such as after the first chunk of an `streamedQuery` or when `setQueryData` sets data while the fetch is in flight. - If the data is fresh, it resolves immediately without refetching. - While the query is disabled (`enabled: false`), it waits until the query is enabled, so it never resolves for a query that stays disabled. On the server, this blocks the render, see [SSR](./ssr.md#suspense-of-a-query-that-stays-disabled-blocks-the-render-on-the-server). - If the fetch fails, it resolves with the query result in the error state. It rejects with the error only when `throwOnError` is (or returns) `true`. diff --git a/examples/lit/chat/README.md b/examples/lit/chat/README.md index c6886b103bd..31b8dc879a8 100644 --- a/examples/lit/chat/README.md +++ b/examples/lit/chat/README.md @@ -4,7 +4,7 @@ A chat UI that streams the answer into the query cache with `streamedQuery`. ## How it works -- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)`, a `queryOptions` factory whose `queryFn` is `experimental_streamedQuery` (imported as `streamedQuery`) with `staleTime: Infinity`. +- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)`, a `queryOptions` factory whose `queryFn` is `streamedQuery` with `staleTime: Infinity`. - `src/services/messages/api.ts` returns an async iterable that yields the answer one word at a time with a random delay and stops when the `signal` aborts. - `src/chat-message.ts` calls `createQueryController` with `messagesQueries.detail(...)`. `data` grows as chunks arrive and is joined into the answer, and `isFetching` stays `true` until the stream ends. - `src/main.ts` subclasses `QueryClientProvider` to set the shared `QueryClient` and renders one `` per submitted question. diff --git a/examples/lit/chat/src/services/messages/queries.ts b/examples/lit/chat/src/services/messages/queries.ts index 725690a6d3e..d7170295d1b 100644 --- a/examples/lit/chat/src/services/messages/queries.ts +++ b/examples/lit/chat/src/services/messages/queries.ts @@ -1,7 +1,4 @@ -import { - queryOptions, - experimental_streamedQuery as streamedQuery, -} from '@tanstack/lit-query' +import { queryOptions, streamedQuery } from '@tanstack/lit-query' import { messagesAPI } from './api' export const messagesQueries = { diff --git a/examples/preact/chat/README.md b/examples/preact/chat/README.md index ac2bf126e06..b1fdad29290 100644 --- a/examples/preact/chat/README.md +++ b/examples/preact/chat/README.md @@ -4,7 +4,7 @@ A chat UI that streams the answer into the query cache with `streamedQuery`. ## How it works -- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)`, a `queryOptions` factory whose `queryFn` is `experimental_streamedQuery` (imported as `streamedQuery`) with `staleTime: Infinity`. +- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)`, a `queryOptions` factory whose `queryFn` is `streamedQuery` with `staleTime: Infinity`. - `src/services/messages/api.ts` returns an async iterable that yields the answer one word at a time with a random delay and stops when the `signal` aborts. - In `src/index.tsx`, each `ChatMessage` calls `useQuery(messagesQueries.detail(id, question))`. `data` grows as chunks arrive and is joined into the answer, and `isFetching` stays `true` until the stream ends. diff --git a/examples/preact/chat/src/services/messages/queries.ts b/examples/preact/chat/src/services/messages/queries.ts index 1ba364a7676..66af719ae7f 100644 --- a/examples/preact/chat/src/services/messages/queries.ts +++ b/examples/preact/chat/src/services/messages/queries.ts @@ -1,7 +1,4 @@ -import { - queryOptions, - experimental_streamedQuery as streamedQuery, -} from '@tanstack/preact-query' +import { queryOptions, streamedQuery } from '@tanstack/preact-query' import { messagesAPI } from './api' export const messagesQueries = { diff --git a/examples/react/chat/README.md b/examples/react/chat/README.md index f0c2d6b4eb6..0038af417c2 100644 --- a/examples/react/chat/README.md +++ b/examples/react/chat/README.md @@ -4,7 +4,7 @@ A chat UI that streams the answer into the query cache with `streamedQuery`. ## How it works -- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)` with `queryOptions`, using `experimental_streamedQuery` (imported as `streamedQuery`) as the `queryFn` and `staleTime: Infinity`. +- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)` with `queryOptions`, using `streamedQuery` as the `queryFn` and `staleTime: Infinity`. - `src/services/messages/api.ts` returns an async iterable that yields a canned answer word by word with random delays and stops when the query's `signal` is aborted. - `src/index.tsx` renders a `ChatMessage` per question, which calls `useQuery(messagesQueries.detail(id, question))`. `data` is the array of chunks received so far, joined into the answer, and `isFetching` stays `true` until the stream ends. diff --git a/examples/react/chat/src/services/messages/queries.ts b/examples/react/chat/src/services/messages/queries.ts index 06714a6e093..cb77b306611 100644 --- a/examples/react/chat/src/services/messages/queries.ts +++ b/examples/react/chat/src/services/messages/queries.ts @@ -1,7 +1,4 @@ -import { - queryOptions, - experimental_streamedQuery as streamedQuery, -} from '@tanstack/react-query' +import { queryOptions, streamedQuery } from '@tanstack/react-query' import { messagesAPI } from './api' export const messagesQueries = { diff --git a/examples/solid/chat/README.md b/examples/solid/chat/README.md index a8615531f0e..b83b94d71ff 100644 --- a/examples/solid/chat/README.md +++ b/examples/solid/chat/README.md @@ -4,7 +4,7 @@ A chat UI that streams the answer into the query cache with `streamedQuery`. ## How it works -- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)` with `queryOptions`. Its `queryFn` is `streamedQuery` (imported as `experimental_streamedQuery`), which appends each chunk from `streamFn` to `data` as it arrives, and `staleTime: Infinity` keeps a finished answer from being refetched. +- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)` with `queryOptions`. Its `queryFn` is `streamedQuery`, which appends each chunk from `streamFn` to `data` as it arrives, and `staleTime: Infinity` keeps a finished answer from being refetched. - `src/services/messages/api.ts` returns an async iterable that yields a canned answer word by word with random delays and stops when the query's `signal` is aborted. - `src/index.tsx` renders a `ChatMessage` per question, which reads the streamed words from `useQuery` and joins them. `isFetching` stays `true` until the stream ends, which shows the "..." indicator. diff --git a/examples/solid/chat/src/services/messages/queries.ts b/examples/solid/chat/src/services/messages/queries.ts index 9aa23d7cc94..a8c8d7ffd96 100644 --- a/examples/solid/chat/src/services/messages/queries.ts +++ b/examples/solid/chat/src/services/messages/queries.ts @@ -1,7 +1,4 @@ -import { - queryOptions, - experimental_streamedQuery as streamedQuery, -} from '@tanstack/solid-query' +import { queryOptions, streamedQuery } from '@tanstack/solid-query' import { messagesAPI } from './api' export const messagesQueries = { diff --git a/examples/svelte/chat/README.md b/examples/svelte/chat/README.md index 194eaa300a9..ebf6e966b26 100644 --- a/examples/svelte/chat/README.md +++ b/examples/svelte/chat/README.md @@ -4,7 +4,7 @@ A chat UI that streams the answer into the query cache with `streamedQuery`. ## How it works -- `src/lib/services/messages/queries.ts` defines `messagesQueries.detail(id, question)` with `queryOptions`. Its `queryFn` is `streamedQuery` (imported as `experimental_streamedQuery`), which appends each chunk from `streamFn` to `data` as it arrives, and `staleTime: Infinity` keeps a finished answer from being refetched. +- `src/lib/services/messages/queries.ts` defines `messagesQueries.detail(id, question)` with `queryOptions`. Its `queryFn` is `streamedQuery`, which appends each chunk from `streamFn` to `data` as it arrives, and `staleTime: Infinity` keeps a finished answer from being refetched. - `src/lib/services/messages/api.ts` returns an async iterable that yields a canned answer word by word with random delays and stops when the query's `signal` is aborted. - `src/lib/Example.svelte` keeps the list of questions and renders a `ChatMessage` for each one. - `src/lib/ChatMessage.svelte` reads the streamed words from `createQuery` and joins them. `isFetching` stays `true` until the stream ends, which shows the "..." indicator. diff --git a/examples/svelte/chat/src/lib/services/messages/queries.ts b/examples/svelte/chat/src/lib/services/messages/queries.ts index e0b59bd6902..210ba24d077 100644 --- a/examples/svelte/chat/src/lib/services/messages/queries.ts +++ b/examples/svelte/chat/src/lib/services/messages/queries.ts @@ -1,7 +1,4 @@ -import { - queryOptions, - experimental_streamedQuery as streamedQuery, -} from '@tanstack/svelte-query' +import { queryOptions, streamedQuery } from '@tanstack/svelte-query' import { messagesAPI } from './api' export const messagesQueries = { diff --git a/examples/vue/chat/README.md b/examples/vue/chat/README.md index fbe75f9b0dc..329812871f4 100644 --- a/examples/vue/chat/README.md +++ b/examples/vue/chat/README.md @@ -5,7 +5,7 @@ A chat UI that streams the answer into the query cache with `streamedQuery`. ## How it works - `src/services/messages/api.ts` returns an async iterable that yields a canned answer one word at a time with a random delay, and stops when the `signal` aborts. -- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)`, a `queryOptions` factory whose `queryFn` is `experimental_streamedQuery` (imported as `streamedQuery`). Each yielded word is appended to `data`, and `staleTime: Infinity` keeps a finished answer from refetching. +- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)`, a `queryOptions` factory whose `queryFn` is `streamedQuery`. Each yielded word is appended to `data`, and `staleTime: Infinity` keeps a finished answer from refetching. - `src/ChatMessage.vue` passes a getter to `useQuery` for one question and renders `data` joined into a sentence, with `isFetching` marking the answer as still in progress. - `src/App.vue` adds a question with a new `crypto.randomUUID()` id on submit, so every question gets its own query. diff --git a/examples/vue/chat/src/services/messages/queries.ts b/examples/vue/chat/src/services/messages/queries.ts index e037b087813..95835fff282 100644 --- a/examples/vue/chat/src/services/messages/queries.ts +++ b/examples/vue/chat/src/services/messages/queries.ts @@ -1,7 +1,4 @@ -import { - queryOptions, - experimental_streamedQuery as streamedQuery, -} from '@tanstack/vue-query' +import { queryOptions, streamedQuery } from '@tanstack/vue-query' import { messagesAPI } from './api' export const messagesQueries = { diff --git a/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx b/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx index 114c58e6011..5669f3a17e5 100644 --- a/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx +++ b/packages/preact-query/src/__tests__/useSuspenseQuery.test.tsx @@ -7,8 +7,8 @@ import { QueryCache, QueryClient, QueryErrorResetBoundary, - experimental_streamedQuery, skipToken, + streamedQuery, useQueryErrorResetBoundary, useSuspenseInfiniteQuery, useSuspenseQuery, @@ -1071,7 +1071,7 @@ describe('useSuspenseQuery', () => { function Page() { const { data } = useSuspenseQuery({ queryKey: key, - queryFn: experimental_streamedQuery({ + queryFn: streamedQuery({ streamFn: () => numberGenerator(), }), }) diff --git a/packages/query-core/src/__tests__/streamedQuery.test-d.tsx b/packages/query-core/src/__tests__/streamedQuery.test-d.tsx index cc269242046..be30db67d9a 100644 --- a/packages/query-core/src/__tests__/streamedQuery.test-d.tsx +++ b/packages/query-core/src/__tests__/streamedQuery.test-d.tsx @@ -1,5 +1,5 @@ import { describe, expectTypeOf, it } from 'vitest' -import { streamedQuery } from '../streamedQuery' +import { streamedQuery } from '..' import type { QueryClient, QueryFunction, QueryKey, QueryMeta } from '..' function numberStream(): AsyncIterable { diff --git a/packages/query-core/src/__tests__/streamedQuery.test.tsx b/packages/query-core/src/__tests__/streamedQuery.test.tsx index fdbff0f8296..75e3307b61b 100644 --- a/packages/query-core/src/__tests__/streamedQuery.test.tsx +++ b/packages/query-core/src/__tests__/streamedQuery.test.tsx @@ -1,7 +1,6 @@ import { createKey, sleep } from '@tanstack/query-test-utils' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { QueryClient, QueryObserver } from '..' -import { streamedQuery } from '../streamedQuery' +import { QueryClient, QueryObserver, streamedQuery } from '..' describe('streamedQuery', () => { let queryClient: QueryClient diff --git a/packages/query-core/src/index.ts b/packages/query-core/src/index.ts index 366633ac0c2..c45e8e84f6b 100644 --- a/packages/query-core/src/index.ts +++ b/packages/query-core/src/index.ts @@ -44,7 +44,7 @@ export { } from './utils' export type { MutationFilters, QueryFilters, SkipToken, Updater } from './utils' -export { streamedQuery as experimental_streamedQuery } from './streamedQuery' +export { streamedQuery } from './streamedQuery' // Types export type { diff --git a/packages/query-core/src/streamedQuery.ts b/packages/query-core/src/streamedQuery.ts index 357d752ad98..a8cd5ce91df 100644 --- a/packages/query-core/src/streamedQuery.ts +++ b/packages/query-core/src/streamedQuery.ts @@ -8,13 +8,13 @@ import type { import type { FetchSignalContext } from './utils' type BaseStreamedQueryParams = { - /** The function that returns an `AsyncIterable` to stream data from. */ + /** Returns an `AsyncIterable` or a promise that resolves to one. */ streamFn: ( context: QueryFunctionContext, ) => AsyncIterable | Promise> /** * Defines how refetches are handled. - * - `'reset'` (default): erases all data and puts the query back into `pending` state. + * - `'reset'` (default): resets the query to its initial state before reading the stream. * - `'append'`: appends new data to the existing data. * - `'replace'`: writes all data to the cache once the stream ends. */ @@ -35,13 +35,12 @@ type ReducibleStreamedQueryParams< TQueryKey extends QueryKey, > = BaseStreamedQueryParams & { /** - * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an - * array, since there is no default way to accumulate non-array chunks. + * Combines the accumulated data with the next chunk. Provide `initialValue` with a custom reducer. */ reducer: (acc: TData, chunk: TQueryFnData) => TData /** - * The value used while the first chunk is being fetched, and returned if the stream yields no - * values. Required together with a custom `reducer`. + * The starting value for the reducer when there is no cached data or when + * `refetchMode` is `'replace'` during a refetch. */ initialValue: TData } @@ -51,10 +50,12 @@ type StreamedQueryParams = | ReducibleStreamedQueryParams /** - * This is a helper function to create a query function that streams data from an AsyncIterable. - * Data will be an Array of all the chunks received. - * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that. - * The query will stay in fetchStatus 'fetching' until the stream ends. + * Creates a query function that streams data from an `AsyncIterable`. + * By default, the query collects chunks into an array in the order they arrive. + * If there is no cached data, the first chunk moves the query from `pending` to `success`. + * If the stream ends without producing any chunks, the query uses the cached data or + * the initial value. With a `'replace'` refetch, it uses the initial value. + * The query's `fetchStatus` stays `fetching` while the stream is active. * Explicit cancellation stops further cache updates, even if `streamFn` does not read `signal`. * If `streamFn` does not read `signal`, the stream continues after the last observer unsubscribes. * @param options - The `streamFn` that returns an AsyncIterable to stream data from, and the optional diff --git a/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx b/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx index 4217a2147bb..dde40112782 100644 --- a/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx +++ b/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx @@ -7,9 +7,9 @@ import { QueryCache, QueryClient, QueryErrorResetBoundary, - experimental_streamedQuery, keepPreviousData, skipToken, + streamedQuery, useQueryErrorResetBoundary, useSuspenseInfiniteQuery, useSuspenseQuery, @@ -1272,7 +1272,7 @@ describe('useSuspenseQuery', () => { function Page() { const { data } = useSuspenseQuery({ queryKey: key, - queryFn: experimental_streamedQuery({ + queryFn: streamedQuery({ streamFn: () => numberGenerator(), }), }) diff --git a/packages/vue-query/src/__tests__/useQuery.test.ts b/packages/vue-query/src/__tests__/useQuery.test.ts index cc4cda950a2..e4e2fdc9bd1 100644 --- a/packages/vue-query/src/__tests__/useQuery.test.ts +++ b/packages/vue-query/src/__tests__/useQuery.test.ts @@ -1,8 +1,8 @@ import { QueryObserver, - experimental_streamedQuery, noop, skipToken, + streamedQuery, } from '@tanstack/query-core' import { createKey, sleep } from '@tanstack/query-test-utils' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -962,7 +962,7 @@ describe('useQuery', () => { const query = useQuery({ queryKey: key, - queryFn: experimental_streamedQuery({ + queryFn: streamedQuery({ streamFn: () => numberGenerator(), }), }) diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts index 13c27557031..3b75e3aacc1 100644 --- a/scripts/generate-docs.ts +++ b/scripts/generate-docs.ts @@ -18,8 +18,8 @@ type PackageReferenceDocsConfig = { exclude?: Array simplifyLitQueriesControllerTypes?: boolean trimGeneratedMarkdown?: boolean - // Maps a generated page's path (relative to outputDir, no extension) to the flat - // `docs/framework//reference/.md` URLs it replaced, so old links/bookmarks redirect + // Maps a generated page's path (relative to outputDir, no extension) to the URLs it replaced, + // so old links and bookmarks redirect // instead of falling through to the framework docs index. See https://github.com/TanStack/query/issues/11371 redirectFrom?: Record> } @@ -918,17 +918,30 @@ const packages: Array = [ entryPoints: [resolve(__dirname, '../packages/angular-query/src/index.ts')], tsconfig: resolve(__dirname, '../packages/angular-query/tsconfig.json'), outputDir: resolve(__dirname, '../docs/framework/angular/reference'), + redirectFrom: { + 'functions/streamedQuery': [ + 'framework/angular/reference/functions/experimental_streamedQuery', + ], + }, }, { entryPoints: [resolve(__dirname, '../packages/svelte-query/src/index.ts')], tsconfig: resolve(__dirname, '../packages/svelte-query/tsconfig.json'), outputDir: resolve(__dirname, '../docs/framework/svelte/reference'), + redirectFrom: { + 'functions/streamedQuery': [ + 'framework/svelte/reference/functions/experimental_streamedQuery', + ], + }, }, { entryPoints: [resolve(__dirname, '../packages/solid-query/src/index.ts')], tsconfig: resolve(__dirname, '../packages/solid-query/tsconfig.json'), outputDir: resolve(__dirname, '../docs/framework/solid/reference'), redirectFrom: { + 'functions/streamedQuery': [ + 'framework/solid/reference/functions/experimental_streamedQuery', + ], 'functions/infiniteQueryOptions': [ 'framework/solid/reference/infiniteQueryOptions', ], @@ -954,6 +967,9 @@ const packages: Array = [ tsconfig: resolve(__dirname, '../packages/vue-query/tsconfig.json'), outputDir: resolve(__dirname, '../docs/framework/vue/reference'), redirectFrom: { + 'functions/streamedQuery': [ + 'framework/vue/reference/functions/experimental_streamedQuery', + ], 'functions/infiniteQueryOptions': [ 'framework/vue/reference/infiniteQueryOptions', ], @@ -1070,18 +1086,31 @@ const packages: Array = [ 'framework/react/reference/notifyManager', ], 'variables/environmentManager': ['reference/environmentManager'], - 'functions/experimental_streamedQuery': ['reference/streamedQuery'], + 'functions/streamedQuery': [ + 'reference/streamedQuery', + 'framework/react/reference/functions/experimental_streamedQuery', + ], }, }, { entryPoints: [resolve(__dirname, '../packages/preact-query/src/index.ts')], tsconfig: resolve(__dirname, '../packages/preact-query/tsconfig.json'), outputDir: resolve(__dirname, '../docs/framework/preact/reference'), + redirectFrom: { + 'functions/streamedQuery': [ + 'framework/preact/reference/functions/experimental_streamedQuery', + ], + }, }, { entryPoints: [resolve(__dirname, '../packages/lit-query/src/index.ts')], tsconfig: resolve(__dirname, '../packages/lit-query/tsconfig.json'), outputDir: resolve(__dirname, '../docs/framework/lit/reference'), + redirectFrom: { + 'functions/streamedQuery': [ + 'framework/lit/reference/functions/experimental_streamedQuery', + ], + }, simplifyLitQueriesControllerTypes: true, trimGeneratedMarkdown: true, },