kadirahq / flow-router

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

[ssr] The _transform function is not applied during SSR #592

Open chmac opened 8 years ago

chmac commented 8 years ago

Also posted the issue here dburles/meteor-collection-helpers#60.

Using dburles:collection-helpers and SSR, we find that the helpers are undefined during SSR.

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

I tried to follow the SSR code and figure out what was going on, where the issue might lie, but didn't quite make it. I think that SSR (and it's dependency on FastRender) cause subscriptions and collections to be "wrapped" to add some magic, and those "wrapped" versions don't get the helpers added.

Is there a fix or a workaround? Or should we consider these two packages incompatible?

chmac commented 8 years ago

The problem is that the collection's _transform() is not applied during SSR. We found a workaround by adding something like this to our data component:

if (Meteor.isServer) {
  doc = Collection._transform(doc)
}

It's a bit of a pain, and we need to do it manually in every component that fetches data, but it's less work than a massive refactor of helpers, etc.