Skip to content

Commit

Permalink
docs: add documentation for gcTime error for react-query (TanStack#6544)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
brendenehlers and TkDodo authored Dec 18, 2023
1 parent 0f2db04 commit e02557e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/react/guides/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ In case you are creating the `QueryClient` for every request, React Query create

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.

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.

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.

Alternatively, you can set a smaller `gcTime`.
Expand Down

0 comments on commit e02557e

Please sign in to comment.