Skip to content

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

@buglessir

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.

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