Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR not waiting for data #431

Closed
timothyarmes opened this issue Nov 29, 2015 · 7 comments
Closed

SSR not waiting for data #431

timothyarmes opened this issue Nov 29, 2015 · 7 comments

Comments

@timothyarmes
Copy link

Hi,

My getMeteorData() looks something like this:

getMeteorData() {

   const sub = Meteor.subscribe('mySub')
   console.log('subscribed');   

   const result = Meteor.find().fetch()
   console.log(result);   

   return { result }
}

Rendering on the client works correctly, however on the server the result is always empty, so the SSR rendered data is null.

The publish code is slightly unusual in that I'm using an aggregation and pushinh the results to the collection manually:

   const result = OKKs.aggregate(options);

   if (result != null) {
      for (let item of result) {

         // Add the result to the subscription.
         console.log(item);
         sub.added('okks', item._id, item);
      }
   }

Here I can see that the items are successfully added to the subscription before the call to subscribe returns, so the console looks like this:

{ item 1 }
{ item 2 }
{ item ... } 
subscribed
[]

Why is the result of the find still empty?

I've noticed when doing SSR that components aren't rerendered with the results of async callbacks, so I assume that FlowRouter is waiting for data from any subscriptions before allowing the rendered to happen. Is my unusual subscription causing an issue?

Tim

@arunoda
Copy link
Contributor

arunoda commented Nov 30, 2015

This is a custom publication. So, you need to call sub.ready() after initial set of data has been added.

If that doesn't worked out, try to create a sample repo and send it. You can fork and use my hello-meteor-react project.

@timothyarmes
Copy link
Author

Sorry, I didn't show all the code. I am calling sub.ready(). I'll see if I can create the repo.

@timothyarmes
Copy link
Author

Hi,

As requested, here's a repo:

https://github.com/timothyarmes/hello-react-meteor

With JS turned on it works as before. With it turned off there's no published data.

Regards,

Tim

@arunoda
Copy link
Contributor

arunoda commented Nov 30, 2015

I'll check this.

On Mon, Nov 30, 2015 at 1:25 PM timothyarmes [email protected]
wrote:

Hi,

As requested, here's a repo:

https://github.com/timothyarmes/hello-react-meteor

With JS turned on it works as before. With it turned off there's no
published data.

Regards,

Tim


Reply to this email directly or view it on GitHub
#431 (comment)
.

@arunoda
Copy link
Contributor

arunoda commented Nov 30, 2015

Yep. I think there is an issue here with custom publications.
I'll check the issue.

@arunoda
Copy link
Contributor

arunoda commented Nov 30, 2015

Had a bug in FastRender and fixed it. Try updating to the latest version of flow-router-ssr (v3.7.0)

@timothyarmes
Copy link
Author

Thanks, that's fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants