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] SSR and Counts #533

Closed
SachaG opened this issue Feb 19, 2016 · 8 comments
Closed

[SSR] SSR and Counts #533

SachaG opened this issue Feb 19, 2016 · 8 comments

Comments

@SachaG
Copy link

SachaG commented Feb 19, 2016

I'm using the publish-counts package to publish a count of how many total posts exist on the server to the client.

Publish-counts only works on the client, so it doesn't work when called server-side with FlowRouter-SSR. So I decided to do this instead:

const totalCount = Meteor.isClient ? Counts.get("totalPostsCount") : Posts.find().count();

But it seems like even when called on the server, Posts.find() returns the data that would be published to the client, not the total data available server-side. Is this expected behavior? Or am I mistaken?

@arunoda
Copy link
Contributor

arunoda commented Feb 19, 2016

@SachaG that's a feature. In the server (with SSR) you can't access to the whole database. You only have access to the data fetched from publications.

I assume, you can can Counts.get from the server as well.
I'm doing a blog post today, you'll get more info on designing a SSR app with that.

@SachaG
Copy link
Author

SachaG commented Feb 19, 2016

OK, that's what I thought. Any way to bypass this? Maybe Posts.findAll() or something? Anyway I'll wait for the blog post (but apart from that, SSR now works in Telescope Nova!)

And no, Counts.get doesn't work on the client. See percolatestudio/publish-counts#80

@arunoda
Copy link
Contributor

arunoda commented Feb 19, 2016

@SachaG You shouldn't bypass that. That's the idea. In the server, SSR is also just like the client for data.

@SachaG
Copy link
Author

SachaG commented Feb 19, 2016

I understand the principle, but how else can I deal with this issue? Writing Counts.get("myCount") on the server doesn't make sense, because myCount only gets registered inside the publication – which is not called on the server… So it sounds like the publish-count package would need to be refactored quite a bit, but in the meantime I was hoping there would be an easier fix.

(Also ideally I'd prefer avoiding using Meteor.isClient, so I agree with you)

@arunoda
Copy link
Contributor

arunoda commented Feb 19, 2016

Actually, it don't need much refactoring. Just run this code on the server as well.
See: https://github.com/percolatestudio/publish-counts/blob/master/client/publish-counts.js

Then Counts.get also works on the SSR context. That's why we build FlowRouter SSR in the first place :)

@SachaG
Copy link
Author

SachaG commented Feb 19, 2016

I might be wrong but I thought @tmeasday was saying it's not that simple?

@arunoda
Copy link
Contributor

arunoda commented Feb 19, 2016

That's possible because we created that :)

@arunoda
Copy link
Contributor

arunoda commented Feb 28, 2016

I hope we can close this since we are clear with how FlowRouter SSR do things.

@arunoda arunoda closed this as completed Feb 28, 2016
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