Skip to content

Invalidate/Refetch Promises not resolving when paused #5054

@alexanderdavide

Description

@alexanderdavide

Describe the bug

When invalidating/refetching a query without internet connection, the corresponding promises don't resolve until the connection reestablishes and the query itself resolves.

Your minimal, reproducible example

https://codesandbox.io/s/react-query-refetch-invalidate-promises-not-resolving-when-paused-hsk41e

Steps to reproduce

  1. Use the provided Code Sandbox.
  2. Mock offline behavior using React Query Devtools.
  3. Click on Invalidate/Refetch buttons.
  4. Understand that the promises aren't resolving. You can refer to the logs in console.
  5. Disable mocking offline behavior.
  6. Understand that the promises now resolve.

Expected behavior

I suspect invalidateQueries to only mark queries as stale which is also what Query Invalidation documentation explains. This can lead to refetching of queries but invalidateQueries isn't bound to refetching or its success. In so far, invalidateQueries should resolve after having marked the query as stale. Since I understand refetch just as a more 'aggressive' invalidateQueries, it should behave the same.

How often does this bug happen?

Only the first time when fetching without internet. Fetching again while the previous promise still isn't resolving, results in a resolved promise.

Screenshots or Videos

No response

Platform

  • OS: Linux, Android
  • Platform: Browser, React Native
  • 110.0.5481.178, 0.68.2

TanStack Query version

4.24.10

TypeScript version

4.3.5

Additional context

No response

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