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

Prevent situations where a logout can trigger unsubscribe of ready() data #24

Open
theodorDiaconu opened this issue Jun 19, 2018 · 2 comments

Comments

@theodorDiaconu
Copy link
Contributor

theodorDiaconu commented Jun 19, 2018

Flow:

  • User logged out
  • Subscription changed -> returned error
  • Component Autorun re-rrun (because .fetch() was reactive) and .ready() and .fetch() were run in the same autorun context
  • Left hanging subscription run due to memory leak

This was the fix, but I'm not sure exactly why, I leave it here to merge it later.

  const subscriptionError = new ReactiveVar();

  return withTracker((props) => {
    const query = handler(props);

    const subscriptionHandle = query.subscribe({
      onStop(err) {
        if (err) {
          subscriptionError.set(err);
        }
      },
      onReady() {
        subscriptionError.set(null);
      },
    });

    const isReady = subscriptionHandle.ready();

    return {
      isReady,
      query,
      config,
      props,
      subscriptionError,
    };
  })(dataTracker(errorTracker(QueryComponent)));
}```

```const dataTracker = withTracker(({ query, config, props, isReady, subscriptionError }) => ({
  grapher: {
    data: query.fetch(),
    isLoading: !isReady,
    error: subscriptionError,
  },
  query,
  config,
  props,
}));```
@Floriferous
Copy link
Contributor

Just tried to clone this package and make these changes but it did not work.

Here's my setup:

  • Layout -> query for current logged in user
    • Subcomponent -> query for data that has a firewall checking for a logged in user

When the user logs out, the subcomponent query is rerun, and the firewall throws an error, crashign the app on the client.

@theodorDiaconu
Copy link
Contributor Author

@Floriferous it's normal for the subcomponent to re-run.

You logout -> Your subscriptions get updated. If you did not unmount the component, it may take some time before React unmounts it thus triggering unsubscribe. I would advise you to do something like history.push('/login'); Meteor.logout(), so you already unmount anything unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants