T
TanStack•3y ago
quickest-silver

Query client on SSR memory

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,
},
},
})
);
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?
9 Replies
sunny-green
sunny-green•3y ago
Why would it be created on each render? It's inside the useState lazy initializer function...
quickest-silver
quickest-silverOP•3y ago
just that if you have
useState({})
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! thanks @TkDodo 🔮 !
sunny-green
sunny-green•3y ago
we've fixed this in v4. I guess you're on v3 ?
quickest-silver
quickest-silverOP•3y ago
yep. indeed. Set a set infinity cache time on the server
quickest-silver
quickest-silverOP•3y ago
before
No description
quickest-silver
quickest-silverOP•3y ago
after
quickest-silver
quickest-silverOP•3y ago
No description
sunny-green
sunny-green•3y ago
Infinity is the default in v4 🙂 good to see that it helped
quickest-silver
quickest-silverOP•3y ago
yup.. read that in some github issues you were in using react query for a very large uk gov contract

Did you find this page helpful?