flow-router: flow-router-ssr : call server method in route action from server : cannot find data in collection if not subscribed

There are some collections that I do not wish to publish (like Meteor.users, or internal stats) and some datas I want to get in straight json and not as cursors (for pagination purpose mostly). So I want to get them from a Meteor.call. No subscription and no reactivity.

It works client side, but not server side.

To reproduce, clone the repo of the hello react meteor application : https://github.com/arunoda/hello-react-meteor. Then in the router.jsx, change that code :

action: function() {
  ReactLayout.render(BlogLayout, {
    content: <PostList />
  });
}

To that one :

action: function() {
  Meteor.call('getPost', function (err, res) {
    console.log('err : ', err);
    console.log('res : ', res);
    ReactLayout.render(BlogLayout, {
      content: <PostList />
    });
  });
}

And add the method to retrieve a post :

 if( Meteor.server )
    Meteor.methods({
      getPost(){
        return Posts.findOne();
      }
    });

You can now find the retrieved post in the client and server console. It works.

But now, comment the subscription :

//this.register('posts', Meteor.subscribe('posts', selector));

Client side, it keeps working, but server side, the result is now undefined (the view is broken now of course, but we don’t care for this example).

Is it a bug ? Is it supposed to work that way ? Is there a workaround ?

Here are the stack traces :

Call from server :

Trace: undefined
at [object Object].Meteor.methods.getPost (both/router.jsx:14:19)
at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
at packages/ddp/livedata_server.js:1530:1
at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
at [object Object]._.extend.apply (packages/ddp/livedata_server.js:1529:1)
at [object Object]._.extend.call (packages/ddp/livedata_server.js:1472:1)
at FlowRouter.route.action (both/router.jsx:25:12)
at packages/meteorhacks:flow-router-ssr/server/route.js:19:1
at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
at packages/meteorhacks:flow-router-ssr/server/route.js:13:1
at doCall (packages/meteorhacks:picker/lib/implementation.js:98:1)

Call from client

Trace: one
at [object Object].Meteor.methods.getPost (both/router.jsx:13:19)
at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
at packages/ddp/livedata_server.js:648:1
at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
at packages/ddp/livedata_server.js:647:1
at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
at packages/ddp/livedata_server.js:546:1

From what I understand, this is a context matter. But I have no idea how to solve that.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

I’m having the same problem too! But with react-mounter. Has this been resolved? Or FR SSR won’t support this?

Hi,

Just adding my support to this. Being able to have the result of a Meteor method available would be very helpful.

I currently use a meteor method to get an array of _ids and then subscribe to the those _ids. It lets me keep the initial ordering of the documents whilst retaining reactivity (this article describes it in more detail: http://tomkelsey.co.uk/reining-in-the-reactivity-with-meteor/)

I haven’t worked out how to do this with SSR as I can’t wait on the method call on the client - so react reports a mismatch between the client and server code.

If @fabien-h’s PR solves the issue I’m all for it 👍