Skip to content

Commit f5a0cec

Browse files
authored
docs(ssr): Hydration caveat for Next.js' rewrites (#3209)
Adds a small section for a caveat about hydration when using some specific feature/configuration of Next.js
1 parent 11f4ea9 commit f5a0cec

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/src/pages/guides/ssr.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ function Posts() {
107107

108108
As demonstrated, it's fine to prefetch some queries and let others fetch on the queryClient. This means you can control what content server renders or not by adding or removing `prefetchQuery` for a specific query.
109109

110+
### Caveat for Next.js rewrites
111+
112+
There's a catch if you're using [Next.js' rewrites feature](https://nextjs.org/docs/api-reference/next.config.js/rewrites) together with [Automatic Static Optimization](https://nextjs.org/docs/advanced-features/automatic-static-optimization) or `getStaticProps`: It will cause a second hydration by React Query. That's because [Next.js needs to ensure that they parse the rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewrite-parameters) on the client and collect any params after hydration so that they can be provided in `router.query`.
113+
114+
The result is missing referential equality for all the hydration data, which for example triggers whereever your data is used as props of components or in the dependency array of `useEffect`s/`useMemo`s.
115+
110116
## Using Other Frameworks or Custom SSR Frameworks
111117

112118
This guide is at-best, a high level overview of how SSR with React Query should work. Your mileage may vary since there are many different possible setups for SSR.

0 commit comments

Comments
 (0)