Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Race condition in useSubscription causing 'loading' to remain true #3802

@davetapley

Description

@davetapley

Intended outcome:

When a subscription's initial data is returned by the GraphQL server,
the useSubscription hook should:

  • Set loading to false.
  • Provide the data in data.
  • Do this 100% of the time.

Actual outcome:

Approximately 30% of the time (in my case) the initial data is returned by the GraphQL server but loading remains true and data remains undefined.

How to reproduce the issue:

Based on my investigate I believe this issue will occur in any application which uses useSubscription. However due to its intermittent / race condition nature it will be highly dependent on the complexity of the React application, and network conditions.

I have posted a screen cast here demonstrating the issue here.

Root cause:

As identified in the video, I believe the root cause is a race condition in /packages/hooks/src/data/SubscriptionData.ts which implicitly requires that isMounted will be set to true before updateResult is called, and this is not always the case.

I haven't investigated further, but it's possible this is also the root cause for:
#3774 #3488 #3361 #3425 #3090 #2899

Version

  System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    npm: 6.10.3 - ~/.nvm/versions/node/v10.15.3/bin/npm
  Browsers:
    Chrome: 79.0.3945.117
    Firefox: 72.0.1
    Safari: 13.0.4
  npmPackages:
    @apollo/react-common: 3.1.3 => 3.1.3 
    @apollo/react-hoc: 3.1.3 => 3.1.3 
    @apollo/react-hooks: 3.1.3 => 3.1.3 
    apollo-boost: 0.4.7 => 0.4.7 
    apollo-cache-inmemory: 1.6.5 => 1.6.5 
    apollo-client: 2.6.8 => 2.6.8 
    apollo-link: 1.2.13 => 1.2.13 
    apollo-link-context: 1.0.19 => 1.0.19 
    apollo-link-http: 1.5.16 => 1.5.16 
    apollo-link-ws: 1.0.19 => 1.0.19 
    react-apollo: 3.1.3 => 3.1.3 

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