Skip to content

Define when suspense queries should be refetched and when they should throw #1059

@trevorwhealy

Description

@trevorwhealy

Describe the bug
When a user does client-side navigation to return to a previously visited page (react-router-dom), the useQuery hook is not invoked again, even if the query has been marked as invalid. This is an issue because the server value could change in a different browser session or device and the useQuery data value would no longer be in sync.

To Reproduce
Created a reproducible environment for testing the bug here:
https://codesandbox.io/s/ping-pong-react-query-client-guqhn
Important files: src/index.js and src/components/Demo.js

Steps to reproduce the behavior:

  1. Visit Page 1, note the number of pings, and click the increment button.
  2. In the mutation's onSuccess handler, we invalidate the queryCache and navigate to Page 2.
  3. Open a new tab and simulate the ping mutation by simply hitting this URL a few times:
    -- https://1675g.sse.codesandbox.io/ping-increase
  4. Navigate back to Page 1 via Link or browser back button and note that the value is only incremented by 1.
  5. If you refresh Page 1, you'll notice that the value now reflects the actual server value.

Expected behavior
On return to Page 1 from Page 2, I would expect the useQuery hook to fetch the latest server value.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions