question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:20 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kokjinsamcommented, Apr 11, 2016

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

1reaction
tomwasdcommented, Nov 15, 2015

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 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

kadirahq/flow-router: Carefully Designed Client Side ... - GitHub
FlowRouter is a very simple router for Meteor. It does routing for client-side apps and does not handle rendering itself.
Read more >
meteorhacks:flow-router-ssr - Packosphere
Flow Router is a minimalistic router which only handles routing and subscriptions. You can't have any kind of reactive code inside the router....
Read more >
Why is Collection.find() not working on my Meteor client?
The problem here is that a subscribe operation is asynchronous, as it has to fetch data from the server. The solution is to...
Read more >
URLs and Routing - Meteor Guide
In a web application, routing is the process of using URLs to drive the user interface (UI) ... Since the server is not...
Read more >
Chapter 8. Routing using Iron.Router - Meteor in Action
Tom wrote one of the first routers for Meteor, called meteor-router ... This means if you click a link, there's no request back...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found