#Query client on SSR memory

1 messages · Page 1 of 1 (latest)

radiant nest
#

Does anyone know if this


function CustomApp({ Component, pageProps }: AppProps<AdditionalAppProps>) {
  const [queryClient] = React.useState(
    () => new QueryClient({
        defaultOptions: {
          queries: {
            refetchOnWindowFocus: false,
            refetchInterval: false,
            refetchIntervalInBackground: false,
          },
        },
      })
  );

Would create a new object in nextJS for each session? on a standard react app that object would be created each time a component renders. Wasn't sure for next as this is app component. Anyone know?

untold violet
#

Why would it be created on each render? It's inside the useState lazy initializer function...

radiant nest
#

just that if you have
useState({}) in a component then it forces a re render?

#

ah i see

#

totally different

#

Gunna share some interesting thihngs with cacheTime soon. We had big issues with node garbage collection and running out of memory on a big app

#

changed the cacheTime to infinity on the server

#

the CPU time dropped like a stone!

radiant nest
#

thanks @untold violet !

untold violet
#

we've fixed this in v4. I guess you're on v3 ?

radiant nest
#

yep. indeed. Set a set infinity cache time on the server

#

before

#

after

untold violet
#

Infinity is the default in v4 🙂

#

good to see that it helped

radiant nest
#

yup.. read that in some github issues you were in