Skip to content

persistWithLocalStorage is hydrating with the wrong cacheTime #1600

@melanieseltzer

Description

@melanieseltzer

Describe the bug
It appears that after hydrating from local storage, the cacheTime gets reset back to the default of 5 minutes.

I use 1000 * 60 * 60 * 24 which is 86400000 ms (24 hours). You can see in my GIF that this is correctly set at first, but as soon as I refresh the page and it hydrates from local storage, the cacheTime is set back to the default of 300000 ms (5 minutes).

It will then garbage collect the queries after 5 minutes if you navigate away from the app, which removes them from local storage, rendering local storage pretty useless...

To Reproduce
https://codesandbox.io/s/react-query-persist-bug-4k32q

  1. Click on some buttons to save some queries
  2. Observe in devtools that the cacheTime is correct (86400000)
  3. Refresh the page
  4. Observe that the cacheTime is now 300000
  5. Navigate away from the codesandbox for 5 minutes and come back to it
  6. Observe that there are no longer any queries saved in local storage

Expected behavior
Uses the correct cacheTime so queries are not forced out of local storage early.

Screenshots
Kapture 2021-01-07 at 20 20 41

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome
  • Version: 3.5.6

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions