iron-router-progress
iron-router-progress copied to clipboard
subscribe(...).wait() in Router.onBeforeAction causes "You called wait() after calling ready() inside the same computation tree."
Looks like there is problem with this peace of code:
Router.onBeforeAction(function(pause) {
var loadingTemplate;
if (this.ready()) {
ready() causes error. I think this hook should be last in queue of hooks.
E.g. this is my code:
var mustBeSignedIn = function(pause) {
this.subscribe('items').wait();
};
Router.onBeforeAction(mustBeSignedIn);
Router.map(function () {
this.route('items', {
path: '/'
});
});
It produces this error:
Exception from Tracker recompute function: Error:
You called wait() after calling ready() inside the same computation tree.
You can fix this problem in two possible ways:
...
But this version (without global hook) works ok:
Router.map(function () {
this.route('items', {
path: '/',
onBeforeAction: mustBeSignedIn
});
});
I guess we need an all around better way of dealing with this. Because the loading hook is probably okay unless people are calling wait()
on a subscription in some downstream hook. Maybe we should just force people to do their subscriptions in the subscriptions or waitOn functions. So if they call wait() outside of those functions iron router throws an error. What do you guys think?
I think its ok to call wait after ready.
Usually subscription params not changed just on recall. So dependency will be called only once. Subscription will be not reinited as params wasn't changed.
Maybe I'm missing something, but I think iron-router in this case just make its using more complicated without reasonable needs.
If somebody will catch infinite recursive call - it will be seen and fixed for particular case.
Many people were reporting 100% cpu and infinite invalidation loops. But I'd have to go back and look into it again specifically because too many new things to think about. Go poke around if you want though and if there's room for improvement, let's make it better. For some history, I think the issue that was being solved can be summarized like this:
dep = new Tracker.Dependency;
Tracker.autorun(function () {
console.log("I run forever :-(");
dep.depend();
dep.changed();
});
Is this still a problem with the latest IR and IRP? If so, please reopen. :)
I think this is still an issue as i'm seeing it in the current release. Can you re-open?