Skip to content

Forced refetchQueries isn't updating cache when key is changed during fetch #341

@krashdifferent

Description

@krashdifferent

I'm seeing an issue with force refetching queries when the query key changes during the refetch

Workflow:

  • A mutation is performed on a object in cache with a significant stale time
  • refetchQueries is used on the relevant query key with the force option
  • Before the fetch can return, the query key given to useQuery is set to undefined
  • Some time after the refetch has returned but before the data is "stale" the original query key is used again
  • Instead of getting the updated values, useQuery returns the original cache before the refetch was requested

codesandbox used to replicate the issue: https://codesandbox.io/s/black-dream-l20v5?file=/src/App.js

A bit of an edge case but one users quickly found. Current workaround involves using the refechQueries promise to lock out the UI in ways that prevent the query key from changing until the refecth completes. This creates a less responsive UI for the 90% use case. Is there another way to mark the cache as stale before staleTime is reached?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions