Skip to content

fetchMore race conditions when paginating after change to useQuery variablesΒ #11630

@Athelian

Description

@Athelian

Issue Description

I have a strange issue where two successive calls to fetchMore will cause a bug only if the query was changed once before.

Reproduction outline

  • fetchpolicy = "network-only"
  • paginating with a:
    • custom merge function
    • custom read function
  • query can be updated to include one extra field of the same object
  • make three requests of 10 items each as soon as:
    1. page loads (βœ… no problem)
    2. query updates (🐞 bug)

Link to Reproduction

Code sandbox

Reproduction Steps

  1. Press the "change query" button
    Result: data returned from useQuery is stale, despite sequential calls to fetchMore (fetchMore updates not present).

Example workarounds:

  • Reduce the number of times fetchMore is called, (instead of two times just one time: change line 46 - change number 30 to 20)
  • In the merge function, if the query is changed (detect by: incoming is first ten items), then throw away the merged result and return only incoming
  • In the original query, call more than one field. In the updated query, call fewer of those fields (seems to return cached result despite using "network-only")

@apollo/client version

3.9.5

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