Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

README.md

18 lines1.6 KB

1# TanStack Solid Query Streaming Example (SolidStart)
2​
3Streaming SSR, with one route per case: prefetching, deferred and streamed queries, hydration, mixed queries, batch methods and errors.
4​
5Built with [SolidStart](https://start.solidjs.com).
6​
7## How it works
8​
9- `src/services/posts/queries.ts` and `src/services/users/queries.ts` define `postsQueries.detail(...)` and `usersQueries.detail(...)` with `queryOptions`. Their `sleep` and `simulateError` arguments are part of the `queryKey` and are passed to `src/services/posts/api.ts` and `src/services/users/api.ts` to add latency or throw.
10- `src/components/user-info.tsx` and `src/components/post-viewer.tsx` read the data with `useQuery` and forward a `deferStream` prop. `src/components/query-boundary.tsx` wraps a query result in `<Suspense>` and an `ErrorBoundary` with a retry button that calls `refetch`.
11- `src/routes/streamed.tsx` streams each query's result to the client when it resolves on the server, while `src/routes/deferred.tsx` and `src/routes/with-error.tsx` set `deferStream` so the server waits for those queries before it sends HTML. `src/routes/mixed.tsx` sets `deferStream` only on the quick `UserInfo` query, so its HTML waits for that query while `PostViewer` streams in afterward.
12- `src/routes/prefetch.tsx` starts the user query in the route's `preload` with `queryClient.query(...)`, and `src/routes/hydration.tsx` compares the query state on the server, right after hydration and on the client.
13- `src/routes/batch-methods.tsx` switches the scheduler used to batch updates with `notifyManager.setScheduler`.
14​
15To run this example:
16​
17- `npm install`
18- `npm run dev`