Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior of skip option in useQuery leading to stale results #11631

Open
hangindev opened this issue Feb 29, 2024 · 1 comment
Open

Comments

@hangindev
Copy link

hangindev commented Feb 29, 2024

Issue Description

Consider the following component:

function Component({ id, skip }) {
  const { data } = useQuery(GET_DATA, { variables: { id }, skip });
  return data;
}

If the variables change while the query is being skipped, I would expect that, when the component re-renders with skip = false, the query is made with up-to-date variables and data would then reflect the GraphQL query result with those variables applied. However, in some cases (see link to reproduction), the data remains stale and the query is never fetched.

Link to Reproduction

https://codesandbox.io/p/sandbox/dazzling-violet-9p6hlz

Reproduction Steps

  1. Click "Toggle View" twice
  2. Change character
  3. Click "Toggle View" again
  4. Observe stale view data

@apollo/client version

3.9.5

@hangindev hangindev changed the title Inconsistent behaviour of skip option in useQuery leading to stale result Inconsistent Behavior of skip Option in useQuery Leading to Stale Results Feb 29, 2024
@hangindev hangindev changed the title Inconsistent Behavior of skip Option in useQuery Leading to Stale Results Inconsistent behavior of skip option in useQuery leading to stale results Feb 29, 2024
@phryneas
Copy link
Member

Thank you for the reproduction!

Just some notes:

From digging a bit, it seems that in the fetchPolicy: "standby" case, updateWatch is not called, which results in updateLastDiff being called without options for the wrong variables - and without options, we cannot identify that the variables are actually wrong.
As a result, the outdated result gets merged in with the new variables.

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

No branches or pull requests

2 participants