Skip to content

SSR and high memory consumption by react-query cache #3284

Answered by TkDodo
meskill asked this question in Q&A
Discussion options

You must be logged in to vote

are you creating the queryClient inside of getServerSideProps / getStaticProps?

export async function getStaticProps() {
   const queryClient = new QueryClient()
 
   await queryClient.prefetchQuery('posts', getPosts)
 
   return {
     props: {
       dehydratedState: dehydrate(queryClient),
     },
   }
 }

but yeah the running timers might actually stop it from being garbage collected by node. Have you tried setting a smaller cacheTime, like 10 seconds? 0 won't work because then it could be empty by the time you call dehydrate...

Profiling the memory leads to the react-query cache internals.

Can you share the profiling results maybe?

Replies: 4 comments 15 replies

Comment options

You must be logged in to vote
3 replies
@meskill
Comment options

@TkDodo
Comment options

@meskill
Comment options

Answer selected by meskill
Comment options

You must be logged in to vote
2 replies
@meskill
Comment options

@phaethon5882
Comment options

Comment options

You must be logged in to vote
9 replies
@TkDodo
Comment options

@c01inQvQ
Comment options

@gavinthomas-valtech
Comment options

@gavinthomas-valtech
Comment options

@TkDodo
Comment options

Comment options

You must be logged in to vote
1 reply
@TkDodo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants