{"action":"created","issue":{"url":"https://api.github.com/repos/kadirahq/flow-router/issues/534","repository_url":"https://api.github.com/repos/kadirahq/flow-router","labels_url":"https://api.github.com/repos/kadirahq/flow-router/issues/534/labels{/name}","comments_url":"https://api.github.com/repos/kadirahq/flow-router/issues/534/comments","events_url":"https://api.github.com/repos/kadirahq/flow-router/issues/534/events","html_url":"https://github.com/kadirahq/flow-router/issues/534","id":135156917,"number":534,"title":"[SSR] Watch out for code order between `find()` and `subscribe()`","user":{"login":"SachaG","id":358832,"avatar_url":"https://avatars.githubusercontent.com/u/358832?v=3","gravatar_id":"","url":"https://api.github.com/users/SachaG","html_url":"https://github.com/SachaG","followers_url":"https://api.github.com/users/SachaG/followers","following_url":"https://api.github.com/users/SachaG/following{/other_user}","gists_url":"https://api.github.com/users/SachaG/gists{/gist_id}","starred_url":"https://api.github.com/users/SachaG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SachaG/subscriptions","organizations_url":"https://api.github.com/users/SachaG/orgs","repos_url":"https://api.github.com/users/SachaG/repos","events_url":"https://api.github.com/users/SachaG/events{/privacy}","received_events_url":"https://api.github.com/users/SachaG/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-21T04:06:55Z","updated_at":"2016-02-21T04:44:23Z","closed_at":"2016-02-21T04:44:23Z","body":"I just ran into a subtle bug with SSR, it's not really an issue but I thought I'd make a note of it in case somebody else has the same problem. \r\n\r\nOn the client (inside a reactive context such as `getMeteorData()`), both of these do basically the same thing:\r\n\r\n```js\r\nMeteor.subscribe(\"myPublication\");\r\nconst data = Posts.find().fetch();\r\nreturn {posts: data};\r\n```\r\n\r\nand\r\n\r\n```js\r\nconst data = Posts.find().fetch();\r\nMeteor.subscribe(\"myPublication\");\r\nreturn {posts: data};\r\n```\r\n\r\nSince the context is reactive, it doesn't matter if you do the `find().fetch()` first or subscribe first, because `find().fetch()` will rerun a second time once the subscription is ready anyway. \r\n\r\nBut when running on the server the order *does* matter! If you call `fetch()` before `subscribe()`, there won't be any data in `Posts` (since FlowRouter SSR only makes available data that you've “published” to simulate the client's state) and `fetch()` will return an empty array. \r\n\r\nSo make sure to always **subscribe first**. "},"comment":{"url":"https://api.github.com/repos/kadirahq/flow-router/issues/comments/186740287","html_url":"https://github.com/kadirahq/flow-router/issues/534#issuecomment-186740287","issue_url":"https://api.github.com/repos/kadirahq/flow-router/issues/534","id":186740287,"user":{"login":"arunoda","id":50838,"avatar_url":"https://avatars.githubusercontent.com/u/50838?v=3","gravatar_id":"","url":"https://api.github.com/users/arunoda","html_url":"https://github.com/arunoda","followers_url":"https://api.github.com/users/arunoda/followers","following_url":"https://api.github.com/users/arunoda/following{/other_user}","gists_url":"https://api.github.com/users/arunoda/gists{/gist_id}","starred_url":"https://api.github.com/users/arunoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arunoda/subscriptions","organizations_url":"https://api.github.com/users/arunoda/orgs","repos_url":"https://api.github.com/users/arunoda/repos","events_url":"https://api.github.com/users/arunoda/events{/privacy}","received_events_url":"https://api.github.com/users/arunoda/received_events","type":"User","site_admin":false},"created_at":"2016-02-21T04:44:23Z","updated_at":"2016-02-21T04:44:23Z","body":"Yeah! This is not a bug anyway :)\r\nI think your PR to the README will address this."}}