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

Server Support #80

Open
SachaG opened this issue Feb 19, 2016 · 18 comments
Open

Server Support #80

SachaG opened this issue Feb 19, 2016 · 18 comments

Comments

@SachaG
Copy link

SachaG commented Feb 19, 2016

Since Counts is only defined on the client, the package doesn't work with server-side rendering. Maybe I could submit a PR for that?

@tmeasday
Copy link
Member

I'm not quite sure it makes sense, because the name -> count mapping comes from the publication body.

@SachaG
Copy link
Author

SachaG commented Feb 19, 2016

Hmm that's true… I guess I'll do this for now then:

    const totalCount = Meteor.isClient ? Counts.get(this.props.publication) : Posts.find().count();

@tmeasday
Copy link
Member

Yup!

On Fri, 19 Feb 2016 at 14:06 Sacha Greif [email protected] wrote:

Hmm that's true… I guess I'll do this for now then:

const totalCount = Meteor.isClient ? Counts.get(this.props.publication) : Posts.find().count();


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

@SachaG
Copy link
Author

SachaG commented Feb 19, 2016

I guess if we wanted to solve this in a cleaner way, we'd have to register the count outside of the publication, and then only reference it inside the publication? Or maybe not have it in the publication at all?

@tmeasday
Copy link
Member

Looks like Arunodas thing works different to how I thiught
On Fri, 19 Feb 2016 at 4:52 PM, Sacha Greif [email protected]
wrote:

I guess if we wanted to solve this in a cleaner way, we'd have to register
the count outside of the publication, and then only reference it inside the
publication? Or maybe not have it in the publication at all?


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

@tmeasday
Copy link
Member

You should definitely give it a try

@SachaG
Copy link
Author

SachaG commented Mar 21, 2016

I don't know if this is related to the latest FlowRouterSSR or if this has been happening all along and I just now noticed it, but calling Counts.publish() inside a publication seems to be preventing FlowRouter from subscribing to that publication when performing SSR.

@arunoda any thoughts about this?

@boxofrox
Copy link
Contributor

@SachaG, could you resubmit the FlowRouterSSR problem as a separate issue? It'll certainly help users with the same problem that may not realize this discussion is buried under a closed topic.

@sungwoncho
Copy link

I am having the same issue as @SachaG. Basically, using FlowRouter SSR, on the server side, I get:

Error when doing SSR. path:/: Object [object Object] has no method 'get'

I thought about moving this file to server, but Counts is already defined in the server. I'd like to help resolve this. How can I proceed?

@boxofrox
Copy link
Contributor

boxofrox commented Jun 4, 2016

@sungwoncho sorry for the late response, I'm currently out of town. Unfortunately I'm not familiar with FlowRouter SSR, so I'm restricted to one technique for troubleshooting at this time. I need a code example using publish-counts and flowrouter-ssr that reproduces this issue, with instructions explaining how to use the app to produce the error and what the expected result is. A github repo of a meteor app is most preferred as the example, though it need not be the project you're working on. A new meteor app project that only produces the error is sufficient.

If you can provide that then I can dig further.

Otherwise, your best bet is likely to code isServer/Client checks that swap out publish-counts functions for a server-only variation.

@SachaG
Copy link
Author

SachaG commented Jun 5, 2016

I was actually thinking about this again yesterday and I think creating a server-only Counts.get() function would work.

The main issue is how to store the counts. We could put them in an object inside Counts on the server, but they need to be identified with a unique session-specific variable. And we probably also need a way to clean them up when the session ends to avoid having that object become huge?

@SachaG
Copy link
Author

SachaG commented Jun 5, 2016

Also just to clarify, there's two separate issues here (my bad for mixing them up):

  • Calling Counts.publish() inside a publication seems to be preventing FlowRouter from subscribing to that publication when performing SSR.
  • Counts.get() doesn't have a server-side equivalent.

@SachaG
Copy link
Author

SachaG commented Jun 5, 2016

Actually i's not that easy, because as far as I can tell there is no way to get a session ID from within SSR code… See kadirahq/flow-router#640

@sungwoncho
Copy link

@boxofrox I made a new repo with a reproduction of the error. See here. I am no longer using FlowRouter SSR at the moment, but I can help if there is a need.

@SachaG
Copy link
Author

SachaG commented Jun 5, 2016

@sungwoncho thanks! btw, what are you using? React Router? Or regular FlowRouter?

@sungwoncho
Copy link

sungwoncho commented Jun 5, 2016

@SachaG I am using the regular FlowRouter.

@boxofrox
Copy link
Contributor

boxofrox commented Jun 5, 2016

Thanks for the repo example. If I have time this evening, I'll dig through it, otherwise I'll start tomorrow.

@SachaG
Copy link
Author

SachaG commented Jun 6, 2016

FWIW I decided to implement a simpler version of this package myself. This is what I ended up with:

https://github.com/meteor-utilities/react-list-container/blob/master/lib/cursorcounts.js

I couldn't figure out a way to uniquely identify a user so I used another approach: I'm uniquely identifying the cursor instead, based on the publication name and subscription terms.

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