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

Error Observable cancelled prematurely get's thrown #7608

Closed
capaj opened this issue Jan 22, 2021 · 68 comments · Fixed by #9701
Closed

Error Observable cancelled prematurely get's thrown #7608

capaj opened this issue Jan 22, 2021 · 68 comments · Fixed by #9701

Comments

@capaj
Copy link
Contributor

capaj commented Jan 22, 2021

Sorry that I cannot provide more info.
I may get some time to try and reproduce this in codesandbox in the future, but for now I just wanted to have a linkable bug reference to put into our codebase.
For now we have this hackfix in ErrorBoundary component to get around this:

  componentDidCatch(error: Error) {
    captureException(error)

    if (error.message === 'Observable cancelled prematurely') {
      console.warn(error) // this is an annoying error getting thrown by apollo client 3.3.x. Some future versions might be okay, but it's the safest to leave this here
      // easiest to get this is to use login link on a user profile page and open it in incognito window, There it happens 100% of the times
      location.reload() // slightly hacky, but we can't think of a better hotfix ATM
      return
    }
    this.setState({ error })
  }

Intended outcome:
no error is thrown no matter how we mount/dismount providers.
If this indeed happens when a provider is unmounted by react then it should be caught by apollo-client because at that point we really don't care about these observables and their values at all.

Actual outcome:
this error is thrown:

Uncaught Error: Observable cancelled prematurely
  | ApolloError | @ | index.js:26
  | (anonymous) | @ | QueryManager.js:535
  | (anonymous) | @ | asyncMap.js:11
  | (anonymous) | @ | asyncMap.js:11
  | notifySubscription | @ | Observable.js:140
  | flushSubscription | @ | Observable.js:121
  | (anonymous) | @ | Observable.js:174
  | (anonymous) | @ | Observable.js:73
  | Promise.then (async) |   |  
  | onNewData | @ | useBaseQuery.js:18
  | error | @ | QueryData.js:240
  | notifySubscription | @ | Observable.js:140
  | onNotify | @ | Observable.js:179
  | error | @ | Observable.js:240
  | (anonymous) | @ | iteration.js:4
  | iterateObserversSafely | @ | iteration.js:4
  | error | @ | ObservableQuery.js:26
  | (anonymous) | @ | iteration.js:4
  | iterateObserversSafely | @ | iteration.js:4
  | error | @ | Concast.js:35
  | notifySubscription | @ | Observable.js:140
  | onNotify | @ | Observable.js:179
  | error | @ | Observable.js:240
  | (anonymous) | @ | asyncMap.js:19
  | Promise.then (async) |   |  
  | (anonymous) | @ | asyncMap.js:11
  | notifySubscription | @ | Observable.js:140
  | flushSubscription | @ | Observable.js:121
  | (anonymous) | @ | Observable.js:174
  | (anonymous) | @ | Observable.js:73
  | Promise.then (async) |   |  
  | enqueue | @ | Observable.js:71
  | onNotify | @ | Observable.js:173
  | error | @ | Observable.js:240
  | ../node_modules/@apollo/client/utilities/observables/Concast.js.Concast.deliverLastMessage | @ | Concast.js:86
  | ../node_modules/@apollo/client/utilities/observables/Concast.js.Concast.addObserver | @ | Concast.js:97
  | (anonymous) | @ | Concast.js:11
  | Subscription | @ | Observable.js:197
  | subscribe | @ | Observable.js:279
  | (anonymous) | @ | asyncMap.js:37
  | Subscription | @ | Observable.js:197
  | subscribe | @ | Observable.js:279
  | complete | @ | Concast.js:56
  | notifySubscription | @ | Observable.js:145
  | onNotify | @ | Observable.js:179
  | complete | @ | Observable.js:245
  | (anonymous) | @ | Observable.js:593
  | (anonymous) | @ | Observable.js:73
  | Promise.then (async) |   |  
  | enqueue | @ | Observable.js:71
  | (anonymous) | @ | Observable.js:585
  | Subscription | @ | Observable.js:197
  | subscribe | @ | Observable.js:279
  | complete | @ | Concast.js:56
  | ../node_modules/@apollo/client/utilities/observables/Concast.js.Concast.start | @ | Concast.js:79
  | Concast | @ | Concast.js:71
  | ../node_modules/@apollo/client/core/QueryManager.js.QueryManager.fetchQueryObservable | @ | QueryManager.js:580
  | (anonymous) | @ | ObservableQuery.js:312
  | ../node_modules/@apollo/client/core/Reobserver.js.Reobserver.reobserve | @ | Reobserver.js:18
  | ../node_modules/@apollo/client/core/ObservableQuery.js.ObservableQuery.reobserve | @ | ObservableQuery.js:317
  | ../node_modules/@apollo/client/core/ObservableQuery.js.ObservableQuery.onSubscribe | @ | ObservableQuery.js:294
  | (anonymous) | @ | ObservableQuery.js:13
  | Subscription | @ | Observable.js:197
  | subscribe | @ | Observable.js:279
  | ../node_modules/@apollo/client/react/data/QueryData.js.QueryData.startQuerySubscription | @ | QueryData.js:220
  | ../node_modules/@apollo/client/react/data/QueryData.js.QueryData.getExecuteResult | @ | QueryData.js:150
  | ../node_modules/@apollo/client/react/data/QueryData.js.QueryData.execute | @ | QueryData.js:98
  | (anonymous) | @ | useBaseQuery.js:35
  | useDeepMemo | @ | useDeepMemo.js:6
  | useBaseQuery | @ | useBaseQuery.js:35
  | useQuery | @ | useQuery.js:3
  | useThrowingQuery | @ | useThrowingQuery.ts:18
  | useLoginPageQuery | @ | LoginPage.codegen.tsx:157
  | OauthLoginButtons | @ | OauthLoginButtons.tsx:36
  | renderWithHooks | @ | react-dom.development.js:14985
  | mountIndeterminateComponent | @ | react-dom.development.js:17811
  | beginWork | @ | react-dom.development.js:19049
  | beginWork$1 | @ | react-dom.development.js:23940
  | performUnitOfWork | @ | react-dom.development.js:22776
  | workLoopSync | @ | react-dom.development.js:22707
  | renderRootSync | @ | react-dom.development.js:22670
  | performSyncWorkOnRoot | @ | react-dom.development.js:22293
  | (anonymous) | @ | react-dom.development.js:11327
  | unstable_runWithPriority | @ | scheduler.development.js:646
  | runWithPriority$1 | @ | react-dom.development.js:11276
  | flushSyncCallbackQueueImpl | @ | react-dom.development.js:11322
  | flushSyncCallbackQueue | @ | react-dom.development.js:11309
  | scheduleUpdateOnFiber | @ | react-dom.development.js:21893
  | dispatchAction | @ | react-dom.development.js:16139
  | Promise.then (async) |   |  
  | onNewData | @ | useBaseQuery.js:18
  | next | @ | QueryData.js:230
  | notifySubscription | @ | Observable.js:135
  | onNotify | @ | Observable.js:179
  | next | @ | Observable.js:235
  | (anonymous) | @ | iteration.js:4
  | iterateObserversSafely | @ | iteration.js:4
  | next | @ | ObservableQuery.js:21
  | (anonymous) | @ | iteration.js:4
  | iterateObserversSafely | @ | iteration.js:4
  | next | @ | Concast.js:24
  | notifySubscription | @ | Observable.js:135
  | onNotify | @ | Observable.js:179
  | next | @ | Observable.js:235
  | (anonymous) | @ | Observable.js:589
  | (anonymous) | @ | Observable.js:73
  | Promise.then (async) |   |  
  | enqueue | @ | Observable.js:71
  | (anonymous) | @ | Observable.js:585
  | Subscription | @ | Observable.js:197
  | subscribe | @ | Observable.js:279
  | complete | @ | Concast.js:56
  | ../node_modules/@apollo/client/utilities/observables/Concast.js.Concast.start | @ | Concast.js:79
  | Concast | @ | Concast.js:71
  | ../node_modules/@apollo/client/core/QueryManager.js.QueryManager.fetchQueryObservable | @ | QueryManager.js:580
  | (anonymous) | @ | ObservableQuery.js:312
  | ../node_modules/@apollo/client/core/Reobserver.js.Reobserver.reobserve | @ | Reobserver.js:18
  | ../node_modules/@apollo/client/core/ObservableQuery.js.ObservableQuery.reobserve | @ | ObservableQuery.js:317
  | listeners.add.oqListener | @ | QueryInfo.js:103
  | (anonymous) | @ | QueryInfo.js:115
  | ../node_modules/@apollo/client/core/QueryInfo.js.QueryInfo.notify | @ | QueryInfo.js:115
  | (anonymous) | @ | QueryManager.js:447
  | ../node_modules/@apollo/client/core/QueryManager.js.QueryManager.broadcastQueries | @ | QueryManager.js:447
  | ../node_modules/@apollo/client/core/QueryManager.js.QueryManager.stopQuery | @ | QueryManager.js:433
  | (anonymous) | @ | QueryManager.js:332
  | Promise.finally (async) |   |  
  | ../node_modules/@apollo/client/core/QueryManager.js.QueryManager.query | @ | QueryManager.js:332
  | ../node_modules/@apollo/client/core/ApolloClient.js.ApolloClient.query | @ | ApolloClient.js:133
  | (anonymous) | @ | loadCustomFonts.ts:113
  | (anonymous) | @ | loadCustomFonts.codegen.tsx:64
  | __async | @ | loadCustomFonts.codegen.tsx:64
  | loadCustomFonts | @ | loadCustomFonts.ts:112
  | transitionAppStateToLoggedIn | @ | sessionStore.ts:289
  | AuthSuccess | @ | AuthSuccess.tsx:34
  | renderWithHooks | @ | react-dom.development.js:14985
  | updateFunctionComponent | @ | react-dom.development.js:17356
  | beginWork | @ | react-dom.development.js:19063
  | beginWork$1 | @ | react-dom.development.js:23940
  | performUnitOfWork | @ | react-dom.development.js:22776
  | workLoopSync | @ | react-dom.development.js:22707
  | renderRootSync | @ | react-dom.development.js:22670
  | performSyncWorkOnRoot | @ | react-dom.development.js:22293
  | (anonymous) | @ | react-dom.development.js:11327
  | unstable_runWithPriority | @ | scheduler.development.js:646
  | runWithPriority$1 | @ | react-dom.development.js:11276
  | flushSyncCallbackQueueImpl | @ | react-dom.development.js:11322
  | flushSyncCallbackQueue | @ | react-dom.development.js:11309
  | scheduleUpdateOnFiber | @ | react-dom.development.js:21893
  | dispatchAction | @ | react-dom.development.js:16139
  | Promise.then (async) |   |  
  | onNewData | @ | useBaseQuery.js:18
  | next | @ | QueryData.js:230
  | notifySubscription | @ | Observable.js:135
  | onNotify | @ | Observable.js:179
  | next | @ | Observable.js:235
  | (anonymous) | @ | iteration.js:4
  | iterateObserversSafely | @ | iteration.js:4
  | next | @ | ObservableQuery.js:21
  | (anonymous) | @ | iteration.js:4
  | iterateObserversSafely | @ | iteration.js:4
  | next | @ | Concast.js:24
  | notifySubscription | @ | Observable.js:135
  | onNotify | @ | Observable.js:179
  | next | @ | Observable.js:235
  | (anonymous) | @ | asyncMap.js:13
  | Promise.then (async) |   |  
  | (anonymous) | @ | asyncMap.js:11
  | notifySubscription | @ | Observable.js:135
  | onNotify | @ | Observable.js:179
  | next | @ | Observable.js:235
  | (anonymous) | @ | iteration.js:4
  | iterateObserversSafely | @ | iteration.js:4
  | next | @ | Concast.js:24
  | notifySubscription | @ | Observable.js:135
  | onNotify | @ | Observable.js:179
  | next | @ | Observable.js:235
  | next | @ | bundle.esm.js:29
  | notifySubscription | @ | Observable.js:135
  | onNotify | @ | Observable.js:179
  | next | @ | Observable.js:235
  | (anonymous) | @ | batching.js:84
  | (anonymous) | @ | batching.js:84
  | next | @ | batching.js:82
  | notifySubscription | @ | Observable.js:135
  | onNotify | @ | Observable.js:179
  | next | @ | Observable.js:235
  | (anonymous) | @ | batchHttpLink.js:75
  | Promise.then (async) |   |  
  | (anonymous) | @ | batchHttpLink.js:74
  | Subscription | @ | Observable.js:197
  | subscribe | @ | Observable.js:279
  | ../node_modules/@apollo/client/link/batch/batching.js.OperationBatcher.consumeQueue | @ | batching.js:72
  | (anonymous) | @ | batching.js:105


How to reproduce the issue:
I actually don't know.
This error is thrown on startup of our closed source app, so I cannot share the code.
The app actually has 2 graphQL endpoints and we switch between them depending on the route where the user is and I think this error get's thrown when one apollo provider is unmounted, but I cannot be sure.

Versions

  System:
    OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
  Binaries:
    Node: 12.18.4 - ~/.nvm/versions/node/v12.18.4/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 6.14.6 - ~/.nvm/versions/node/v12.18.4/bin/npm
  Browsers:
    Chrome: 87.0.4280.141
    Firefox: 84.0.2
  npmPackages:
    @apollo/client: ^3.3.7 => 3.3.7 
    @apollo/link-batch-http: ^2.0.0-beta.3 => 2.0.0-beta.3 
    @apollo/link-context: ^2.0.0-beta.3 => 2.0.0-beta.3 
    @apollo/link-error: ^2.0.0-beta.3 => 2.0.0-beta.3 
    @apollo/link-schema: ^2.0.0-beta.3 => 2.0.0-beta.3 
    @apollo/react-components: ^3.1.5 => 3.1.5 
    @apollo/react-testing: ^3.1.4 => 3.1.4 
    apollo-client: ^2.6.10 => 2.6.10 
    apollo-server: ^2.19.2 => 2.19.2 
    apollo-server-express: ^2.19.2 => 2.19.2 
    react-apollo-network-status: ^5.0.1 => 5.0.1 

@JKulhavy91
Copy link

I am experiencing same issue. This had started with version Apollo Client 3.3.0. For now I had downgraded to Apollo Client 3.2.9. . I think that this issue is connected with this feature "Unsubscribing the last observer from an ObservableQuery will once again unsubscribe from the underlying network Observable in all cases, as in Apollo Client 2.x, allowing network requests to be cancelled by unsubscribing." Witch was implemented in Apollo Client 3.3.0

@jochienabuurs
Copy link

Having the same issue here. With me, it also seems to happen when the provider gets unmountend and mounted again.

@PowerKiKi
Copy link
Contributor

Experiencing the same thing in an Angular project, when navigating away from a page where a query is happening.

@kelvin2200
Copy link

We're having the same issue on v.3.3.9. Reverting to 3.2.9 is not an option, because it starts throwing Invariant Violations. Any insight on how to fix this? I can confirm that the Apollo Client Provider is being mounted only ONCE and never re-mounted.

@davidgilbertson
Copy link

Thanks @capaj for posting your workaround, very useful.

To the Apollo folks, it seems to me like throwing an error and breaking the user's app is a bit extreme for this type of issue (especially since it appear to only occur in production mode).

I have no knowledge of this codebase, but could this line not pass true as a second parameter to prevent throwing errors? Or are errors being thrown as a method of communication, and accidentally being allowed out into userland?

@Jscripter-pk
Copy link

Jscripter-pk commented Mar 4, 2021

We are also facing this issue in our React app
Little Explanation :
We are using query to fetch our user .... while querying user we get this error(sometime)

@alperen
Copy link

alperen commented Mar 26, 2021

I was having this problem, I read and research several things about that issue. Unfortunately, the issue is specific to your approach and codebase. You may have a memory leak or unexpected behavior on your product as a code. Already it proofs that because all these comments are pointing to different complaints.

@brainkim
Copy link
Contributor

This definitely looks like a problem on our end and I apologize for all the grief it’s caused. I currently have a lot on my plate, but I will make sure to look at this soon. In the meantime, if anyone created a smallish reproduction using our error template (https://github.com/apollographql/react-apollo-error-template), that would probably magically move this issue up in my TODOs 😇

@brainkim brainkim self-assigned this Apr 28, 2021
@patricknazar
Copy link

It seems I only get this error if returnPartialData = true. Can anyone else confirm this in theirs? I'm trying to put together a repro.

@patricknazar
Copy link

Somewhat of a repro, with angular.

@bchTrackunit
Copy link

This started for me when i used a hook together with a LazyQuery that refetches in a useEffect.

const { someIds } = useSomeHook();

const [getItems, { loading, data }] = useItemsLazyQuery();

React.useEffect(() => {
    getItems({
      variables: {
        ids: someIds,
      },
    });
  }, [someIds]);

if i remove the code from the hook, and move the logic next to the query, it will work fine!

@3nvi
Copy link

3nvi commented May 20, 2021

For us, it happens when you unmount and remount the sasme component really fast.

@patricknazar
Copy link

Any progress? This issue is a huge problem for me.

@carlpaten
Copy link

We're seeing this issue in production as well.

@cornedor
Copy link

Switching the Promise.resolve for a setTimeout(()=>{}, 0) at https://github.com/apollographql/apollo-client/blob/main/src/utilities/observables/Concast.ts#L181 resolves this issue for me. However, I'm not sure if this is a real fix, or that the error is simple suppressed now.

@razor-x
Copy link

razor-x commented Aug 7, 2021

I am seeing this when using react-router <Redirect to={someRoute} />. In my case, I run a GQL query to check the status of the user's account, and in some cases I will redirect the user to a different page. The redirect will happen (url bar updated), but then the error will be thrown at some point during the rendering of the new route.

Using capaj's workaround fixes the issue for now, but it's not an idea UX.

@razor-x
Copy link

razor-x commented Aug 7, 2021

If it helps, I started getting this error after updating @apollo/client 3.3.21 => 3.4.0 and still get it on the latest version 3.4.5.

@nikolnikov
Copy link

I noticed this starting to happen in my Angular app. It generally happens on sign in. You immediately get booted out of the app and it throws the "Observable cancelled prematurely" message. Unfortunately, we cannot reproduce with certainty so it's been a nightmare to try and replicate, much less fix.

@jdehaan
Copy link

jdehaan commented Aug 20, 2021

We are seeing this as well and happens typically during a storm of queries for the same data with cache-first (should resolve to cache). Maybe that helps getting an idea for some repro. Here same thing sometimes works, sometimes not :-/

benjamn added a commit that referenced this issue Aug 20, 2021
Inspired by @cornedor's comment:
#7608 (comment)

Should help with some instances of issue #7608, specifically those with
global unhandled promise rejection errors. I don't know if this is the
full solution, but I believe it is helpful and safe to introduce a delay
before unsubscribing, giving other subscribers a chance to subscribe,
thereby saving the Concast from needing to be cancelled.
@benjamn
Copy link
Member

benjamn commented Aug 20, 2021

@cornedor (and @matthewrc) I actually think the setTimeout trick is good/appropriate, since it takes care of the "Unhandled Promise Rejection" version of this error, which clearly should not be fatal. There's already an asynchronous delay before unsubscribing, so using setTimeout instead shouldn't change the semantics of this code (only the precise timing, and the error behavior).

Partial(?) fix incoming: #8676

@brainkim brainkim removed their assignment Aug 20, 2021
@codingwaysarg
Copy link

In our case the issue was that we had two components rendering at the same time and starting the same subscription. While that was happening, one of them used to unmount due to history.replace in a matching condition. That was causing "observable cancelled prematurely".

@doron-cohen
Copy link

doron-cohen commented May 3, 2022

Adding to what people wrote here. We hit this issue with regular queries (not a subscription) and only when developing locally (with vite). It happens sporadically so it makes me think there is a race condition somewhere.
The HTTP request is being sent and returned but the data doesn't update. Just as if the request dissapeared. Looking at the fetch promise I saw this AbortSignal:

Error: signal is aborted without reason
    at http://localhost:3001/node_modules/.vite/chunk-PBNBAGNW.js?v=ebd50497:432:26
    at cleanupSubscription (http://localhost:3001/node_modules/.vite/chunk-QRI54YM7.js?v=ebd50497:7560:7)
    at notifySubscription (http://localhost:3001/node_modules/.vite/chunk-QRI54YM7.js?v=ebd50497:7616:5)
    at onNotify (http://localhost:3001/node_modules/.vite/chunk-QRI54YM7.js?v=ebd50497:7641:3)
    at SubscriptionObserver2.complete (http://localhost:3001/node_modules/.vite/chunk-QRI54YM7.js?v=ebd50497:7703:9)
    at http://localhost:3001/node_modules/.vite/chunk-PBNBAGNW.js?v=ebd50497:420:22

Downgrading to 3.2.9 like the rest solved the issue.

@chegger
Copy link

chegger commented May 6, 2022

Is there any update to this? This behavior with regards to quick mounts/unmounts seems to be breaking with React 18.

@iserdmi
Copy link

iserdmi commented May 6, 2022

I receive this error in usual query when I set {fetchPolicy: 'cache-and-network'}, when I replace it to {fetchPolicy: 'network'} error disappeared

@benjamn
Copy link
Member

benjamn commented May 9, 2022

I'm cautiously optimistic this problem may be solved once and for all by #9701, which you can test by running

npm i @apollo/client@beta

to get version 3.7.0-alpha.3. If all goes well, these changes should be safe to release in 3.6.4, not waiting from v3.7, so please let us know if/when you have a chance to test the alpha!

@chegger
Copy link

chegger commented May 10, 2022

@benjamn I already go the change to try it out, thanks a lot for the effort!

I am still getting an error when using the useSubscription hook, using react 18.0.0 and @apollo/client 3.7.0-alpha.3, rendering my app in react's StrictMode. As commented here, when i disable StrictMode, the subscription works perfectly fine.

Below is the error that is logged in the dev console in the browser.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'subscriptionFailedCallback')  realtime-subscription-handshake-link.js:327 
    at AppSyncRealTimeSubscriptionHandshakeLink.<anonymous> (realtime-subscription-handshake-link.js:327:1)
    at step (realtime-subscription-handshake-link.js:57:1)
    at Object.next (realtime-subscription-handshake-link.js:38:1)
    at fulfilled (realtime-subscription-handshake-link.js:29:1)

Here you can see the corresponding messages of the subscription in my chrome dev console:

Selection_086

Screenshot of messages when subscription is working When disabling `StricteMode` the , the `messages` look like this:

Selection_087

@ShantanuPhatke
Copy link

I'm cautiously optimistic this problem may be solved once and for all by #9701, which you can test by running

npm i @apollo/client@beta

to get version 3.7.0-alpha.3. If all goes well, these changes should be safe to release in 3.6.4, not waiting from v3.7, so please let us know if/when you have a chance to test the alpha!

3.7.0-alpha.3 resolved the issue for me! Was stuck on v3.2.9 only because the later versions had this issue. Thanks for the fix, hope it is merged in the stable release soon.

@Nedomas
Copy link

Nedomas commented May 16, 2022

Can also confirm that 3.7.0-alpha.3 fixed the Observable cancelled prematurely issue for me too.

@benjamn benjamn removed the 🏓 awaiting-contributor-response requires input from a contributor label May 16, 2022
timegrid added a commit to georga-app/georga-client-react that referenced this issue May 20, 2022
@doflo-dfa
Copy link

doflo-dfa commented May 21, 2022

I receive this error in usual query when I set {fetchPolicy: 'cache-and-network'}, when I replace it to {fetchPolicy: 'network'} error disappeared

This is likely due to the additional time it takes to do the network side of the fetch

@hwillson
Copy link
Member

We believe this is now resolved in @apollo/client@3.6.4 and later - let us know otherwise. Thanks!

@ShantanuPhatke
Copy link

I'm cautiously optimistic this problem may be solved once and for all by #9701, which you can test by running

npm i @apollo/client@beta

to get version 3.7.0-alpha.3. If all goes well, these changes should be safe to release in 3.6.4, not waiting from v3.7, so please let us know if/when you have a chance to test the alpha!

3.7.0-alpha.3 resolved the issue for me! Was stuck on v3.2.9 only because the later versions had this issue. Thanks for the fix, hope it is merged in the stable release soon.

Well, the warning and error logged is fixed. But the problem is that the application doesn't subscribe at all.

In my case particularly, I make a subscription on Page1, then on going to Page2 the previous subscription is 'completed' and second subscription request is initiated. Earlier the error Observable cancelled prematurely used to occur on going to Page2. That error doesn't show up now but the second subscription is not initiated at all. Can't see that in the network tab.

image

@myth535
Copy link

myth535 commented Jul 8, 2022

@benjamn Thanks for your work, but the problem is still not solved, and it's worse in the new versions, because before you could at least see the error and know that something was wrong, but now not even that. Could you re-add the error message? I have a temporary fix using the error

@zodman
Copy link

zodman commented Jul 11, 2022

@myth535 I have the same problem, the useSubscription sometimes works and sometimes don't, feels unstable.
I have to implement my own vanilla javascript subscription:

useEffect(() => {
    const client = backend.apolloClient;
    const susbObservable = client.subscribe({ query: gSubs, variables: vars });
    const subscription = susbObservable.subscribe(
      //onNext
      (value) => {
        if (get(value, 'data.Conversation.key') === conversationKey) {
          setConversation(value.data.Conversation);
        }
      },
      //onError
      (error) => {
        logger.error(conversationKey, error);
      }
    );

    return () => {
      subscription.unsubscribe();
    };
  }, [conversationKey]);

The subscription feels more stable and works well!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.