Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/framework/react/guides/advanced-ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,25 @@ Now, your `getPosts` function can return e.g. `Temporal` datetime objects and th

For more information, check out the [Next.js App with Prefetching Example](../examples/nextjs-app-prefetching).

### Using the Persist Adapter with Streaming

If you're using the persist adapter with the [Streaming with Server Components](#streaming-with-server-components) feature, you need to be careful not to save promises to storage. Since pending queries can be dehydrated and streamed to the client, you should configure the persister to only persist settled queries:

```tsx
<PersistQueryClientProvider
client={queryClient}
persistOptions={{
persister,
// We don't want to save promises into the storage, so we only persist settled queries
dehydrateOptions: { shouldDehydrateQuery: defaultShouldDehydrateQuery },
}}
>
{children}
</PersistQueryClientProvider>
```

This ensures that only successfully resolved or errored queries are persisted to storage, preventing serialization issues with pending promises.

## Experimental streaming without prefetching in Next.js

While we recommend the prefetching solution detailed above because it flattens request waterfalls both on the initial page load **and** any subsequent page navigation, there is an experimental way to skip prefetching altogether and still have streaming SSR work: `@tanstack/react-query-next-experimental`
Expand Down