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


#1

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?


#2

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


#3

I’ll try this in a minute :smiley:


#4

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


#5

@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;

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

#7

@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).


#8

good :smile:

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