Skip to content

Network requests get run twice with React.StrictMode and watchQuery.fetchPolicy: 'cache-and-network' #6832

@meglkts

Description

@meglkts

Intended outcome:

See a component mounted once and queries / network requests issued once in the browser while using React.StrictMode

Actual outcome:

We recently upgraded from @apollo/client:3.0.2 to 3.1.2 and are noticing components re-rendering and queries / network requests getting issued twice with the same data while dependencies remain the same. This issue only occurs in development, where we use React.StrictMode and set the fetchPolicy for watchQuery to cache-and-network. Duplicate queries do not occur if I remove React.StrictMode or use the default fetchPolicy for watchQuery.

How to reproduce the issue:

You can see the issue with a very basic Create React App + Apollo here

  • refresh the inner browser and see the page reload twice
  • inspect the network tab to see graphql request issued twice

I was able to revert to @apollo/client:3.0.0 here with otherwise identical code and the issue is gone and client runs as expected, so it seems to be a regression between 3.0.0 and 3.1.0.

Versions
3.0.0 - works
3.1.0 - regression with double queries

Thanks for any insights!

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