Skip to content

Commit 8471715

Browse files
ofek-frameTkDodo
andauthored
docs: Document possible conflict between PersistQueryClientProvider and SSR streaming (#9979)
* Add docs about PersistQueryClientProvider settings * correct * Apply suggestion from @TkDodo * Apply suggestions from code review --------- Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
1 parent ecf9696 commit 8471715

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

docs/framework/react/guides/advanced-ssr.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,25 @@ Now, your `getPosts` function can return e.g. `Temporal` datetime objects and th
532532

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

535+
### Using the Persist Adapter with Streaming
536+
537+
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 successful queries:
538+
539+
```tsx
540+
<PersistQueryClientProvider
541+
client={queryClient}
542+
persistOptions={{
543+
persister,
544+
// We don't want to save promises into the storage, so we only persist successful queries
545+
dehydrateOptions: { shouldDehydrateQuery: defaultShouldDehydrateQuery },
546+
}}
547+
>
548+
{children}
549+
</PersistQueryClientProvider>
550+
```
551+
552+
This ensures that only successfully resolved queries are persisted to storage, preventing serialization issues with pending promises.
553+
535554
## Experimental streaming without prefetching in Next.js
536555

537556
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`

0 commit comments

Comments
 (0)