My meteor site isn't working well. Problems with latency (I guess)

Hi guys, I have a meteor project that is running at eventpage.meteor.com.
When I test in my machine the site works fine, but when I deploy to meteor.com a error occurs in the router.js throwing a “TypeError: Cannot read property ‘url’ of undefined”. But when I try execute the same code in the Chrome Console the data is correct.

What can it be?

just do:
if(url){
//yourCodeHere
return something;
}
return false;

I’ll try this in a minute :smiley:

just some background info why this can happen:
your url is maybe a reactive Var. Lets say it is.
A reactive Var for example is a Collection Object or a Session Var.

Meteor will run the code without looking if everything is there( thats a js thing)
and meteor will rerun it if something changes in that “computation”. in this case its your router function.

so by wraping around the if statement the code will only run if the url is there.

why is that a good thing?

for example if url is undfined you could show a “loading” template

1 Like

@lampe I’m trying this right now, but still don’t working :/:

        if( !this.ready() ) return false;
	var eventMain = Events.findOne(), image;

	if(eventMain){
		if(eventMain.banner) 
                    image = Images.findOne(eventMain.banner).url();
	} else return false;
if (eventMain) {
  if (eventMain.banner) {
    image = Images.findOne(eventMain.banner);
    if (image) {
      return image.url();
    }
  }
} else {
  return false;
}
1 Like

@lampe thanks for the help with understanding what was happening, now I moved that piece of code to a UI.registerHelper and now it’s working fine (for my sanity’s sake).

good :smile:

if you liked my answere you can always like them :wink: