+ )
+}
diff --git a/examples/preact/ssr/src/entry-client.tsx b/examples/preact/ssr/src/entry-client.tsx
new file mode 100644
index 0000000000..2ad68606ed
--- /dev/null
+++ b/examples/preact/ssr/src/entry-client.tsx
@@ -0,0 +1,31 @@
+import { hydrate } from 'preact'
+import { useState } from 'preact/hooks'
+import { HydrationBoundary, QueryClientProvider } from '@tanstack/preact-query'
+import { PreactQueryDevtools } from '@tanstack/preact-query-devtools'
+import App from './App'
+import { makeQueryClient } from './makeQueryClient'
+import type { DehydratedState } from '@tanstack/preact-query'
+
+declare global {
+ interface Window {
+ __DEHYDRATED_STATE__: DehydratedState
+ }
+}
+
+function Root({ dehydratedState }: { dehydratedState: DehydratedState }) {
+ const [queryClient] = useState(() => makeQueryClient())
+
+ return (
+
+
+
+
+
+
+ )
+}
+
+const rootElement = document.getElementById('root')
+if (!rootElement) throw new Error('Missing #root element')
+
+hydrate(, rootElement)
diff --git a/examples/preact/ssr/src/entry-server.tsx b/examples/preact/ssr/src/entry-server.tsx
new file mode 100644
index 0000000000..80583e1407
--- /dev/null
+++ b/examples/preact/ssr/src/entry-server.tsx
@@ -0,0 +1,46 @@
+import { renderToString } from 'preact-render-to-string'
+import { uneval } from 'devalue'
+import {
+ QueryClientProvider,
+ dehydrate,
+ hydrate,
+ noop,
+} from '@tanstack/preact-query'
+import { PreactQueryDevtools } from '@tanstack/preact-query-devtools'
+import App from './App'
+import { makeQueryClient } from './makeQueryClient'
+import { postsQueries } from './services/posts/queries'
+import { usersQueries } from './services/users/queries'
+
+export async function render() {
+ // The prefetching client: only used to fetch and dehydrate
+ const prefetchClient = makeQueryClient()
+
+ // The posts are critical content: without `.catch(noop)`, a failed fetch
+ // throws here and the server responds with an error status
+ const posts = await prefetchClient.query(postsQueries.list())
+
+ // The author depends on the first post, so prefetch it once its id is known.
+ // It's not critical: on failure it's left out of the dehydrated state and
+ // fetched again on the client
+ const authorId = posts[0]?.userId
+ if (authorId) {
+ await prefetchClient.query(usersQueries.detail(authorId)).catch(noop)
+ }
+
+ const dehydratedState = dehydrate(prefetchClient)
+
+ // The render client: hydrated with the same state, used for renderToString
+ const renderClient = makeQueryClient()
+ hydrate(renderClient, dehydratedState)
+
+ const html = renderToString(
+
+
+
+ ,
+ )
+
+ // `uneval` escapes the state so it can't break out of the