Replies: 2 comments 5 replies
-
If you want a single gcTime, set it globally and don’t set it again on the hooks level. You can also use our |
Beta Was this translation helpful? Give feedback.
-
@TkDodo Thanks for your suggestion. For all I know in the case of nextjs ssr with ssr:false, method useQuery will be executed twice, one time in the server side and it creates an empty Query, another time in the browser and it creates a Query that truly fetch data from the API. Usually developers will set a gcTime according to the api response, if developers forget to set gcTime like isServer? Infinity: 60000, just set gcTime 60000, the empty query will be stored in memory for 60s, and it also makes the prefetch hydrated Query instance that has a lot of data |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/Tseian/nextjs-querycache-memory-leak/blob/main/README.md
In the above recurrence demo, it is difficult for users to find out why the memory increases rapidly. Secondly, even if the problem is found and can be solved by setting all useQuery method parameter cacheTime/gcTime to Infinity. There will be many changes. So I hope that when creating QueryClient, I can pass a parameter like enforceQueryGcTime: Infinity to force all Query instances created through the useQuery method to not remain when the component is unmounted, let the large amount of data injected through prefetch heydrate to be released immediately.
I have created a PR for this, PR. If there is any other better solution, pls just write down in the comment.
Beta Was this translation helpful? Give feedback.
All reactions