Hi, when I call Meteor.subscribe() in componentDidMount(), it gets stopped automatically and I don’t know why since I don’t call the stop() method in the code.
Also this only happens when I reload the page, because if I go to another page and come back to the page of the subscription, it loads normally and don’t stops…
Okay, I finally found where was the problem after a few days of investigation…
I have this code used by the route’s onEnter method that redirects to the login page if the user is not logged in :
const requireAuth = function (nextState, replace, callback) {
Tracker.autorun((c) => {
if (!Meteor.loggingIn()) {
if (!Meteor.userId()) {
const location = nextState.location.pathname;
const url = location || this.path;
replace("/login?redirect=" + encodeURIComponent(url));
}
// c.stop(); // fixme: this causes subscriptions to stop
callback();
}
});
};
As it’s commented in the code, the c.stop() was causing the subscription to stop immediately.
I don’t master the Meteor’s Tracker API, but I guess the subscription relies on the Tracker, that’s why it was stopped.