examples/preact/ssr-streaming
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Preact Query SSR Streaming Example#
Streams server-rendered HTML with Suspense, sending each query's data to the client as it resolves.
How it works#
src/services/wait/queries.tsdefineswaitQueries.detail(wait), aqueryOptionsfactory keyed by['wait', 'detail', wait]that calls/api/wait.src/App.tsxrenders components that calluseSuspenseQuery, each inside its ownSuspenseboundary, plus three that share one boundary.src/entry-server.tsxstarts every query up front withqueryClient.query(...).catch(noop)and subscribes to the query cache. Each query that succeeds isdehydrated on its own and written as a<script>that pushes the state towindow.__QUERY_STATES__before the next chunk ofrenderToPipeableStreamoutput.src/entry-client.tsxcallshydrate(queryClient, state)for every entry inwindow.__QUERY_STATES__before Preact'shydrate.server.jsis an Express server that streams the render into the response and serves/api/wait, which responds after the requested number of milliseconds.
To run this example:
npm installnpm run dev