Templates not displaying after browser reload

After implementing oAuth, my templates are not displaying when reloading the page or restarting a session (load page successfully, close browser, re-open browser and open page). All I see is the background image (which is set via css under “body”).

There are no errors in the client console or the server console.

I am using FlowRouter and useraccounts:flow-routing. When I issue FlowrRouter.reload() or FlowRouter.go(’/route’) in the client console, the page loads successfully. When I enter FlowRouter.getRouteName() it returns the correct route.

I have tried removing useraccounts:flow-routing, along with the oauth packages, same result. I am not sure how/where to troubleshoot this. If I restart the app, pages/templates/routes load successfully

My typical route is configured like this in routes.js:

FlowRouter.route('/routename', {
	name: 'routename',
	action(){
		if(!Meteor.userId()){
			FlowRouter.go('home');
		} else if(Meteor.user()){
			GAnalytics.pageview();
			BlazeLayout.render('MainLayout', {main: 'Routename'});			
			
		}
	}
});

Any suggestions on even how to debug this?

I need history log in your terminal to help you !!
Do you printscreen on your templates name

Thanks for replying @notnoyyyyy, although I don’t understand what you’re asking for? How can I collect the log from the terminal? I assume you mean on app startup? Because otherwise there is no logging/errors/messages at all. And just to be clear, the templates/pages/routes load fine after startup, it’s only after reloading/refreshing the browser page where the templates/pages/routes don’t display anything. And also not sure what you’re asking when you say “Do you printscreen on your templates name”, can you please clarify? thanks!

I should also mention this seems to failing consistently at Galaxy. Locally it’s successfully displaying the pages SOMETIMES, although there seems to be some delay when it does load ok (after page refresh/reload). If I run FlowRouter.reload() in the console it displays right away.

I’ve tried Kadira debug but see no errors/messages at all. The template “loads” but nothing is displayed on the page.

It’s kind of difficult to understand what’s going on – are your templates not displaying at all? Or are they empty? In other words, if you do this:

<template name="Routename">
  <div id="RoutenameWrapper">
    <!-- all of your normal content -->
  </div>
</template>

Do you see the wrapper div and just not the contents? Or do you only see your body?

If the template “loads”, then this indicates a problem at the template level to me. What I will typically do is start putting wrappers around my content with div ids so that I can see just where the cutoff is.

Thanks for the tip on using the wrapper divs @vigorwebsolutions. I implemented that and find that i do not see the div, only the body tag along with a whole host of script tags for all the various packages.

So in other words, that means the template is not “loading”, although FlowRouter.getroutename says the route is “loaded”. and then flowrouter.reload finds it every time consistently. Is there a guard I can put in either in onCreated or even in the route.js configuration to run reload()?

I want to amend a previous note I wrote here that it is not happening locally but only on Galaxy. It is happening locally, just less frequently. I will edit/update the previous statement

One more note - when the page doesn’t load, i do not get the<div id="__blaze-root">. When it loads, obviously I do get that, and the<div id="RouternameWrapper"> is right under it.

My guess is that your check for Meteor.user() in your route is throwing things off. Sometimes the user data is ready, sometimes it isn’t. I would probably move that check to the template level:

<template name="myTemplate">
  {{#if currentUser}}
    <!-- your content -->
  {{/if}}
</template>

If you wanted to keep the logic in the router, I might try:

action () {
  if (!Meteor.userId() && !Meteor.loggingIn()) {
    FlowRouter.go('home');
  } else {
    GAnalytics.pageview();
    BlazeLayout.render('MainLayout', { main: 'Routename' });
  }
}

That really helps @vigorwebsolutions. I added in an else to go to the spinner and it seems to load the spinner route every time instead of just showing nothing, so it’s definitely not “waiting” for Meteor.user() which is why I put that in there. I thought it worked effectively as a guard, but maybe I shouldn’t do that in the route config?

I actually do some currentUser validation in the template pages anyway so I’ll play around with it some to figure out the right solution. Thank you!

1 Like

Yeah, my experience has been that as convenient as it seems to put logic into the router, it never really ends up being that convenient. Good luck!