React-Apollo -- Use <Redirect> instead of history.push()

Here’s something I just discovered that may be helpful to others in a similar situation.

On my app, after a video call, the user is sent to a ratings page. I was sending the user there with history.push(). On the ratings page there are some subscriptions. The subscriptions worked on the first load of the page, but if the user went away and then was returned there via history.push(), the subscriptions stopped working.

I just noticed that if I use a React Router <redirect> instead of history.push(), the subscriptions keep working.


You should check the way you call subscriptions. I’m sure subscriptions work perfectly with history.push().

You can try

const client = useApolloClient();

client.subscribe({ options });

My subscriptions are all working – I only had the anomaly with this particular one. The anomaly appears to be fixed now that I’m using <redirect>. At the same time, what you’re saying makes a lot of sense to me.

Here’s how I’m calling subscriptions:

import {useSubscription} from '@apollo/client';

const useIncomingApptsData = useSubscription(
        variables: {"originatingUserId": Meteor.userId()},
        skip: !Meteor.userId(),
        onSubscriptionData: ({client, subscriptionData, loading}) => {