Skip to content

retry doesn't stop during the internet is disconnected #2900

Closed

Description

@buglessir

I'm using version: 3.25.1

Please consider this example:

const URL = 'https://randomuser.me/api/?results=5&inc=name';

const Example = () => {
  const { error, data, isLoading, refetch } = useQuery('test', () =>
    fetch(URL).then(response => response.json()), {
    refetchOnWindowFocus: false,
    refetchOnReconnect: false,
    retry: 1
  });

  if (isLoading) return <span>Loading...</span>

  if (error) return <span>Error: {error.message} <button onClick={refetch}>retry</button></span>

  return (
    <div>
      <ul>
        {
          data.results.map((item, key) => <li key={key}>{item.name.first} {item.name.last}</li>)
        }
      </ul>
      <button onClick={refetch}>Refetch</button>
    </div>
  )
}

After use the offline mode by DevTools > Network > Throttling, this component doesn't show the loading or even never stop fetching. It's expected to stop fetching and shows the error after once trying...

But after setting this config: retry: false code works correct and shows the error and retrying button.

Activity

  1. changed the title [-]retry doesn't stop during the internet has disconnected[/-] [+]retry doesn't stop during the internet is disconnected[/+] on Nov 8, 2021
  2. TkDodo commented on Nov 8, 2021

    @TkDodo
    Collaborator

    retries are an internal mechanism, and currently, react-query stops retrying if you are offline. You can observe the failureCount returned by useQuery to see if a failure has been detected.

    I'm seeing it more of an issue that calling refetch shouldn't even start fetching if you are currently offline. Right now, it starts the fetch, but then retries "pause" when offline. What it should most likely do is mark the query as stale so that it will be refetched once the user comes back online.

    But any change in this regard would be a breaking change, so we'll have to discuss this for the next major version.

    related:

  3. added this to the v4 milestone on Nov 11, 2021
  4. added
    duplicateThis issue or pull request already exists
    on Nov 11, 2021
  5. TkDodo commented on Nov 11, 2021

    @TkDodo
    Collaborator

    we will be tracking this issue and related ones here from now on:

    The plan is to work on this for the next major version, because it will contain breaking changes. Your feedback would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existsv4

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions