Skip to content

Commit e02557e

Browse files
docs: add documentation for gcTime error for react-query (#6544)
* docs(QueryClient): add documentation for gcTime error * docs(QueryClient): change 'will' to 'can' * docs(react-query): moved gcTime warning to SSR guide * docs(react-query): added paragraph explaining gcTime issue --------- Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
1 parent 0f2db04 commit e02557e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/react/guides/ssr.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ In case you are creating the `QueryClient` for every request, React Query create
541541

542542
On the server, `gcTime` defaults to `Infinity` which disables manual garbage collection and will automatically clear memory once a request has finished. If you are explicitly setting a non-Infinity `gcTime` then you will be responsible for clearing the cache early.
543543

544+
Avoid setting `gcTime` to `0` as it may result in a hydration error. This occurs because the [Hydration Boundary](../reference/hydration#hydrationboundary) places necessary data into the cache for rendering, but if the garbage collector removes the data before the rendering completes, issues may arise. If you require a shorter `gcTime`, we recommend setting it to `2 * 1000` to allow sufficient time for the app to reference the data.
545+
544546
To clear the cache after it is not needed and to lower memory consumption, you can add a call to [`queryClient.clear()`](../reference/QueryClient#queryclientclear) after the request is handled and dehydrated state has been sent to the client.
545547

546548
Alternatively, you can set a smaller `gcTime`.

0 commit comments

Comments
 (0)