score:0

Accepted answer

here's what i think the issue was, and how i solved it.

because i set staletime: infinity in my reactqueryconfigproider, i expected all of my queries to never go stale.

what's different about this query is i invalidate it when something not driven by the ui happens.

i have a session timer in my code that, when the session expired, calls querycache.invalidatequeries('profile') to trigger any ui displaying the profile to re-render.

it appears that if invalidatequeries is ever called outside the context of a query, the settings in reactqueryconfigproider are not observed, so staletime is set to the default, 0.

to resolve this, for the queries i need to invalidate on a timer, i added { staletime: infinity } to the query explicitly:

export const useprofile = () => {
    const { data: session } = usesession();
    const userid = session?.userid;
    return usequery(['profile', userid], getprofile, { staletime: infinity });
};

i won't go so far as to say this is a bug in react-query, but this seems to be a workaround.

score:0

i ran into the same problem, and it was caused by a component that had a child component which used react-query. check your component tree and make sure nothing uses useprofile() outside of <reactqueryconfigprovider>.


Related Query

More Query from same tag