Open History to see the last commit
1# TanStack Solid Query SSR Example (Astro)
2
3A Pokémon search with `keepPreviousData` and `<Suspense>`, rendered as a Solid island.
4
5Built with [Astro](https://astro.build).
6
7## How it works
8
9- `src/services/pokemons/queries.ts` defines `pokemonsQueries.list()` and `pokemonsQueries.detail(id)` with `queryOptions`. The detail options set `placeholderData: keepPreviousData` and `throwOnError: true`.
10- `src/layouts/MainLayout.astro` renders `SolidApp` from `src/components/SolidApp.tsx` as an island with `client:load`, passing the `id` search param read in `src/pages/index.astro`. Astro runs in `output: 'server'` mode, so the island is rendered on the server first.
11- `src/components/SolidApp.tsx` creates the `QueryClient` and wraps the app in `QueryClientProvider` and `<Suspense>`. The side nav and detail view call `useQuery` with `select` to reshape the data and `reconcile` to keep list items stable, and an `ErrorBoundary` shows errors thrown by the detail query.
12- `src/components/Link.tsx` and `src/utils/index.ts` handle client-side navigation with `history.pushState` and a signal that tracks the `id` search param. An `is_server_rendered` query in `src/components/SolidApp.tsx` shows whether the current detail was rendered on the server or the client.
13
14To run this example:
15
16- `npm install`
17- `npm run dev`