Meteor.user() in Fast Render

@copleykj Hello
I used the Meteor.user() method on the client. As follows :


 {
      Meteor.userId()
      ?
          <a onClick={props.ToggleProfile} className="flex flex-col items-center justify-center" href="" >
                <img src={Meteor.user().profile.Avatar}  style={{width:"55px" ,height: 5px",borderRadius:"50%",boxShadow: "0 4px 8px 
                         0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)"}} />
                        <span style={{fontSize: "13px"}} className='pt-1'>
                            پروفایل
                         </span>
          </a>
      : 
          <span>somthing</span>
}

Normally, Fast Render must return the user to the server. And this condition should be checked on the server as well.

But when the server becomes expensive for the first time, this error:

But when I refresh the browser, the error is fixed.

Try putting the if condition on Meteor.user() instead of Meteor.userId(). I recall there being a quirk where Meteor.userId() can exist before Meteor.user() does.

2 Likes

I’m not exactly sure what you mean. It sounds like you get this error on subsequent route changes AFTER the app has loaded and when the user moves between routes. If this is the case, then it is because your data isn’t ready when you try to access the profile property of the user document during rendering. This package can’t help alleviate this issue because the page is already loaded and it’s sending DDP messages over a websocket connection rather than sending html over HTTP. You’ll need to either check if the subscription is ready OR use a guard or optional chaining operator. I’d recommend the former over the latter, since in this case you’ll have a broken image while the data loads.

1 Like