question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem in unsubscribe of useSubscription react hook

See original GitHub issue

When react component unmounts, the useSubscription hook doesn’t unsubscribe stream in server side.

const TestComponent = () => {
  const { loading, error, data } = useSubscription(SUBSCRIPTION);
  
  useEffect(() => {
    return () => {
      // unsubscribe here
    };
  }, []);

  return <div>TestComponent</div>;
};

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
webatomcommented, Jun 7, 2022

@benjamn Hey, I have the same problem

Upgrading to 3.7.0-beta.1 did not help 😦

4reactions
Venryxcommented, Feb 2, 2022

I was about to read through the test files to check whether there are tests set up (to confirm that unsubscribe is being called on subscriptions when they ought to be dropped), but then I opened this: https://github.com/apollographql/apollo-client/blob/a565fd5036b23810f59b49affc69a36cdb434a55/src/core/__tests__/QueryManager/index.ts

And I saw it has 5,881 lines.

And I quietly backed away.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to cancel Graphql subscriptions? - General
@alexb the useSubscription hook will automatically unsubscribe any started subscriptions, when the component using it is unmounted.
Read more >
React unsubscribe from RxJS subscription in useEffect
The issue is that unsubscribe is not actually a function. It's a method on an subscription object. Because of this, the first value...
Read more >
useSubscription | Relay
API reference for useSubscription, a React hook used to subscribe and unsubscribe from a subscription.
Read more >
Cancel / Unsubscribe GraphQL Subscription - Vimal Selvam
This post shows on how to cancel / unubscribe the active GraphQL subscription using Apollo Client package with React.
Read more >
Using Subscriptions with React - GQty
Hook designed to be used for GraphQL Subscriptions. ... Subscribe on-demand; Automatic unsubscribe on component unmount; Automatic updates on cache changes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found