kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 193 forks source link

SSR subscription in composeWithTracker #655

Closed lmachens closed 8 years ago

lmachens commented 8 years ago

Hi, I have a problem with flow-router-ssr and the composer function of react-komposer. In the composer function is a subscription of a collection.

function composer(props, onData) {
  const handle = Meteor.subscribe('collection');

  if (handle.ready()) {
    const collection = Collection.find().fetch();
    onData(null, {collection});
  }
};

export default composeWithTracker(composer)(SomePage);

This is working fine and the SSR renders the page correctly. But when the code is executed I get a "Loading.." indicator for a moment (fast-render). The problem is, that the subscription handle is not ready when it is executed for the first time.

What can I do? Is it possible to deactivate fast-render here and wait for the handle? Thank you

sahanDissanayake commented 8 years ago

Shit I created the same error https://github.com/kadirahq/flow-router/issues/656

Let me remove it

SachaG commented 8 years ago

If fast render is properly preloading your collection data, then the subscription should return ready immediately as far as I know. Maybe @arunoda can correct me on this?

sahanDissanayake commented 8 years ago

Yes the subscription sends ready immediately, but after 1 second on my console log it says ready() as false. which is weird, which make the app goes in to data loading mode again and loads the data from the publication again.. Which just makes no sense and a waste of pre rendering on the server.

sahanDissanayake commented 8 years ago

But the weird part is this is not happening on Localhost.. I tried to slow down the publications using Meteor._sleepForMs, but SSR works perfectly, no reloads or flashes of data loading.

The issue is on Ubuntu server running nginx as per https://www.digitalocean.com/community/tutorials/how-to-deploy-a-meteor-js-application-on-ubuntu-14-04-with-nginx, but deployed with MUPX to port 3000

sahanDissanayake commented 8 years ago

Lets test the same code on a normal server without nginx and deployed with MUPX

sahanDissanayake commented 8 years ago

OHHH Shoot.. Ok seems like its a server setting issue :(

I just setup a server with a simple MUPX setup. it works great.. but not with the nginx setup I linked above

sahanDissanayake commented 8 years ago

Yep definitely nginx issue, I stopped nginx on the server and accessed the url using :3000 and SSR works great

sahanDissanayake commented 8 years ago

Ok After all this I found out it's actually logged in logged out user issue.. If the user is logged out then SSR works.. Everytime I did the previous testing I did not had a login.. Duhh

Now to see why SSR is not working when there is a logged in user

sahanDissanayake commented 8 years ago

I'm done. I'm just going to render everything on the client 😥

SachaG commented 8 years ago

OK, in a funny (or not so funny I guess…) coincidence I'm now running into that exact same problem as well! I'm not using FlowRouter by the way, but React Router. So the problem seems related to either Komposer or Fast-Render.

sahanDissanayake commented 8 years ago

pheww.. good to have someone on the same boat.. Lets do something about this Sacha.. :)

sahanDissanayake commented 8 years ago

do you have a user logged in ??? is the behaviour different when logged in and logged out ? When user is logged out everything is sweet.. but if the user is logged in

I have al sorts of issues.. To start off I have the user object 6 TIMES in Fast render initial data set.. Whyy where does it come from.. I dont know

sahanDissanayake commented 8 years ago

https://github.com/kadirahq/fast-render/issues/174

SachaG commented 8 years ago

Seems to be related to the recent 1.3.3/1.3.4 releases: https://github.com/kadirahq/fast-render/issues/173

That would explain why we both saw the same issue at the same time (and yes it's only when a user is logged in for me too). Also I just downgraded back to 1.3.2.4 and the issue disappeared. So we can probably close this thread and just wait for a fix :)

sahanDissanayake commented 8 years ago

Sweet. everything is working great. Thanks. I have to be careful when I update next time. No more just updating for fun.

Just to be clear are we waiting for a fix from MDG or from Kadira ?

lmachens commented 8 years ago

Downgrading back to 1.3.2.4 fixed it for me too thx.

sahanDissanayake commented 8 years ago

@SachaG are you thinking of upgrading to a newer version of update ? Just double checking with you if you have upgraded or not. If you have not I'll bite the bullet and try to upgrade :)

SachaG commented 8 years ago

No I haven't upgraded, waiting for this to be fixed first.