Open History to see the last commit
1# TanStack Preact Query SSR Streaming Example
2β
3Streams server-rendered HTML with Suspense, sending each query's data to the client as it resolves.
4β
5## How it works
6β
7- `src/services/wait/queries.ts` defines `waitQueries.detail(wait)`, a `queryOptions` factory keyed by `['wait', 'detail', wait]` that calls `/api/wait`.
8- `src/App.tsx` renders components that call `useSuspenseQuery`, each inside its own `Suspense` boundary, plus three that share one boundary.
9- `src/entry-server.tsx` starts every query up front with `queryClient.query(...).catch(noop)` and subscribes to the query cache. Each query that succeeds is `dehydrate`d on its own and written as a `<script>` that pushes the state to `window.__QUERY_STATES__` before the next chunk of `renderToPipeableStream` output.
10- `src/entry-client.tsx` calls `hydrate(queryClient, state)` for every entry in `window.__QUERY_STATES__` before Preact's `hydrate`.
11- `server.js` is an Express server that streams the render into the response and serves `/api/wait`, which responds after the requested number of milliseconds.
12β
13To run this example:
14β
15- `npm install`
16- `npm run dev`