Iron:Router waitOn not working during moment while user is logging in


#1

Just wondering if I am missing something here, but it seems like iron router doesn’t always wait on one of my subscriptions.

This is my main router code.
The reason why I have the waitOn in the main configure object is because I need the collections available for each and every route. For some reason the second collection isn’t always ready at the time the template loads.

Router.configure({
  layoutTemplate: 'layout',
  loadingTemplate: 'loading',
  waitOn: function() {
    return [
      Meteor.subscribe('collection_1', App.Ready),
      Meteor.subscribe('collection_2')
    ];},
  data: function() {
    return CollectionName.findOne();
  }
});

Am I missing something, shouldn’t this work?

I first noticed it after the hot code push, but if I refresh the page it will also often happen.


#2

Try this

data: function() {
 if(this.ready()) return CollectionName.findOne();
}

#3

Hey thanks for the reply.
That didn’t work but made me realise that something else might be the issue.

So I have that route from my original post at the top of my router file, then the page where I see the errors has this specific route:

Router.route('/admin/list', {
  name: 'adminList',
  waitOn: function() {
    return Meteor.subscribe('collection_2', {full_list: true});
  }
});

The errors I am seeing, indicating the collection is not ready come from collection_2.
I don’t set any data scope here.

Any ideas why this is causing me grief?


#4

Make sure you subscribe to the right collection and that there is an actual publish for it. I once had a typo in my code and saw weird results because waitOn did not return.


#5

Ok I think I have worked out what the issue is… lets see if there is a way around this.

I believe the issue is that for a brief moment the user is not logged in.
During that time, the publication, assuming the user is not logged in, returns that it is ready.
I don’t share anything in that publication to users who aren’t logged in.

I tried updating the waitOn, but this isn’t working…
What should I return to indicate that the subscription isn’t ready.

Router.configure({
  layoutTemplate: 'layout',
  loadingTemplate: 'loading',
  waitOn: function() {
    if (!Meteor.loggingIn()) {
      return [
        Meteor.subscribe('collection_1', App.Ready),
        Meteor.subscribe('collection_2')
      ];
    }else{
     return false;
    }
  },
  data: function() {
    return CollectionName.findOne();
  }
});

#6

I tried adding fast-render to assist with the immediate login, still seeing the issue though.