Skip to content

staleTime and suspense true incompatible #1116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
onionhammer opened this issue Sep 30, 2020 · 4 comments
Closed

staleTime and suspense true incompatible #1116

onionhammer opened this issue Sep 30, 2020 · 4 comments

Comments

@onionhammer
Copy link

Describe the bug
useQuery does not pay attention to 'staleTime' to re-invoke the async callback if 'suspense' is set to 'true'.

To Reproduce

    const { data } = useQuery(
        ["somekey", somevalue], 
        () => someAsyncFn(),
        {
            staleTime: 5000,
            // suspense: true // <-- If this line is uncommented, the query will be cached forever, ignoring staleTime
        }
    );

Expected behavior
When a component with this query is remounted after 5 seconds (5000 milliseconds), it should re-invoke someAsyncFn() to re-fetch the data.

@Shaddix
Copy link
Contributor

Shaddix commented Oct 4, 2020

I guess, even if staleTime is zero, the query is forever cached.
Here's a sandbox:
https://codesandbox.io/s/elated-resonance-yqkiw?file=/src/App.js

after click on 'details' the query is unmounted and becomes inactive.
after click on 'go back' the query immediately becomes 'stale' again, without being in 'fetching' state.

(if suspense: false is used, query is re-fetched, which is expected)

@jobn
Copy link

jobn commented Oct 4, 2020

i think it is related to this #1059
with an explanation of the current behaviour here: #1059 (comment)

if you set cacheTime: 0 i think you get the expected behaviour, because the stale query is removed from the cache

@Shaddix
Copy link
Contributor

Shaddix commented Oct 4, 2020

thanks for the link to an issue, it seems to be related, I agree.
Though, setting cacheTime: 0 doesn't help in my case (could be tried on codesandbox above)

@boschni
Copy link
Collaborator

boschni commented Oct 6, 2020

Should be fixed now in v3: https://react-query-beta.tanstack.com/ . Closing this issue in favor of #1059

@boschni boschni closed this as completed Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants