kadirahq / fast-render

Render you app even before the DDP connection is live. - magic?
MIT License
560 stars 80 forks source link

fast render subscriptions empty #38

Closed chrisbutler closed 10 years ago

chrisbutler commented 10 years ago
DDP_SEND: 
Object {msg: "sub", id: "8aCajk2aKNidpBvhR", name: "polls", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "Ysm98tt3gkC7KshNq", name: "polstirs", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "connect", version: "pre1", support: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "login", params: Array[1], id: "1"}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "cxBHWbzZzLzX7DrKs", name: "meteor_autoupdate_clientVersions", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "Fh4vh624QyiTToifc", name: "meteor.loginServiceConfiguration", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "kkk99F2biFAynaggm", name: "_aurora", params: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "8aCajk2aKNidpBvhR", name: "polls", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "Ysm98tt3gkC7KshNq", name: "polstirs", params: Array[0]}
 log.js:7
event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery.js:3259
DDP_RECIEVE: 
Object {msg: "added", collection: "users", id: "89qcZNgZwogBx4og5", fields: Object}
 log.js:7
REVERTING_BACK_TO_ORIGINAL_DDP_HANDLING: log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "roles", id: "RzWFe7zNbJ4wt4rzq", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "roles", id: "Kg3jRXzXMqCRgHXBa", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "roles", id: "MM73x53FidGdaEqJv", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "roles", id: "mNJWj4H2b4awzrutZ", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "roles", id: "jd8WpRgnWfGTBdTMv", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "roles", id: "A6zpGTHRpYezQGh4n", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "updated", methods: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "meteor_autoupdate_clientVersions", id: "603536eead142444bac961533bb66ec1787018b9", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "eventsOnHooksInit", params: Array[0], id: "2"}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "eventsOnLoggedIn", params: Array[0], id: "3"}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "meteor_accounts_loginServiceConfiguration", id: "bXdM7MuSJizMAt6jR", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "_Tevent", params: Array[1], id: "4"}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "polls", id: "7NS2xyo8joHFd72ST", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "polls", id: "gv8irhPQbc44ZcXqX", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "polls", id: "WprcRTTygnQtSdvFP", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "polls", id: "9t6kNPZx3WMJGefcz", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "users", id: "MZYF32yJeirntZ8E8", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "changed", collection: "users", id: "89qcZNgZwogBx4og5", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "kLGHPkaFwdXBWHGzP", name: "polstirs", params: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "_Tevent", params: Array[1], id: "5"}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "JbYxi67PH3Hths3bY", name: "votes", params: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "KiT4EJth9sAdjK7Gx", name: "comments", params: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "updated", methods: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "updated", methods: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "updated", methods: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "updated", methods: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "_Tevent", params: Array[1], id: "6"}
 log.js:7
DDP_RECIEVE: 
Object {msg: "updated", methods: Array[1]}
 log.js:7
chrisbutler commented 10 years ago

however

<script type="text/javascript">
  __fast_render_config = {"subscriptions":{},"serverRoutePath":"/","subscriptionIdMap":{},"loadedSubscriptions":{}}
</script>

and

<script type="text/javascript">
  if(typeof __init_fast_render == 'function') {
    __init_fast_render("%7B%22collectionData%22:%7B%7D%7D")
  }
</script>
DominikGuzei commented 10 years ago

Same for me!

arunoda commented 10 years ago

Are you guys with Meteor 0.8 with Iron Router? If possible send a me a sample version of your routes where I can work on?

chrisbutler commented 10 years ago

i'm on 0.7.0.1 with IR 0.6.4, and my routes are generally all using controllers like this:

PublisherController = FastRender.RouteController.extend({
  waitOn: function () {
      return [
        this.subscribe('polls'),
        this.subscribe('authors')
      ];
  }
});

changing this.subscribe to Meteor.subscribe seems to work

arunoda commented 10 years ago

yep. You've to use Meteor.subscribe.

arunoda commented 10 years ago

Is your problem got solved?

chrisbutler commented 10 years ago

yeah that issue is solved. i'm also getting error: ReferenceError: Session is not defined which i wasn't seeing before, but guarding with if (typeof Session !== 'undefined') is working there

arunoda commented 10 years ago

or you can use Meteor.isClient too.

DominikGuzei commented 10 years ago

For me its not solved yet ;-)

I am on Meteor 0.8.0 and iron-router 0.7.0 Fast Render is at the latest 0.1.23 version

One of my route controllers (all are pretty similar):


@DashboardController = FastRender.RouteController.extend

  template: 'projects_list'

  yieldTemplates:
    dashboard_header: to: 'header'
    dashboard_footer: to: 'footer'

  waitOn: -> Meteor.subscribe 'projects'

  onBeforeAction: -> if Meteor.isClient and Meteor.user() == null then @redirect Router.ROUTES.LOGIN
chrisbutler commented 10 years ago

@arunoda good point, thanks!

arunoda commented 10 years ago

@DominikGuzei shall we make this into a new issue.

Please give me following.

  1. html source of the your app (when there is an error)
  2. apply FastRender.Log.enable() on the browser console and send me the logs
  3. If you can send me re-produceable code, that would be great.
DominikGuzei commented 10 years ago

Actually there is no error, everything works – but Fast Render doesn't send initial data when the page is first loaded.

My Scenario:

A user is logged in and has 1-X projects He is sent to the dashboard route where all projects are listed:

@DashboardController = FastRender.RouteController.extend

  template: 'projects_list'

  yieldTemplates:
    dashboard_header: to: 'header'
    dashboard_footer: to: 'footer'

  waitOn: -> Meteor.subscribe 'projects'

  onBeforeAction: -> if Meteor.isClient and Meteor.user() == null then @redirect Router.ROUTES.LOGIN

It works, the projects get loaded – but over DDP (like normal) This is what gets embedded into the document by fast-render:

  if(typeof __init_fast_render == 'function') {
    __init_fast_render("%7B%22collectionData%22:%7B%7D%7D")
  }

This are the logs I get from fast-render:

DDP_SEND: 
Object
id: "yS7vEfSCEpzmPP7zb"
msg: "sub"
name: "meteor.loginServiceConfiguration"
params: Array[0]
__proto__: Object
 log.js:7
DDP_SEND: 
Object
id: "1"
method: "login"
msg: "method"
params: Array[1]
__proto__: Object
 log.js:7
DDP_SEND: 
Object
id: "nHtsG6eQyji6idupJ"
msg: "sub"
name: "projects"
params: Array[0]
__proto__: Object
 log.js:7
DDP_SEND: 
Object
msg: "connect"
support: Array[1]
version: "pre1"
__proto__: Object
 log.js:7
DDP_SEND: 
Object
id: "1"
method: "login"
msg: "method"
params: Array[1]
__proto__: Object
 log.js:7
DDP_SEND: 
Object
id: "KaLSFmhAsCN2nnRqF"
msg: "sub"
name: "meteor_autoupdate_clientVersions"
params: Array[0]
__proto__: Object
 log.js:7
DDP_SEND: 
Object
id: "yS7vEfSCEpzmPP7zb"
msg: "sub"
name: "meteor.loginServiceConfiguration"
params: Array[0]
__proto__: Object
 log.js:7
DDP_SEND: 
Object
id: "nHtsG6eQyji6idupJ"
msg: "sub"
name: "projects"
params: Array[0]
__proto__: Object
 log.js:7
DDP_RECIEVE: 
Object
collection: "users"
fields: Object
id: "zTBnJnGKZ8Zw8wsE3"
msg: "added"
__proto__: Object
 log.js:7
REVERTING_BACK_TO_ORIGINAL_DDP_HANDLING: log.js:7
DDP_RECIEVE: 
Object
methods: Array[1]
msg: "updated"
__proto__: Object
 log.js:7
DDP_RECIEVE: 
Object
collection: "meteor_autoupdate_clientVersions"
fields: Object
id: "8df4c02a6aec80ec13bfbd70a805b6686900cdfd"
msg: "added"
__proto__: Object
 log.js:7
DDP_RECIEVE: 
Object
msg: "ready"
subs: Array[1]
__proto__: Object
 log.js:7
DDP_RECIEVE: 
Object
msg: "ready"
subs: Array[1]
__proto__: Object
 log.js:7
DDP_RECIEVE: 
Object
collection: "projects"
fields: Object
id: "HTavSiDGuAcy5Px94"
msg: "added"
__proto__: Object
 log.js:7
DDP_RECIEVE: 
Object
msg: "ready"
subs: Array[1]
__proto__: Object
 log.js:7
arunoda commented 10 years ago

Does you routes can be available on the Server Side?

DominikGuzei commented 10 years ago

I think they are available on both sides. I put them in a top-level folder named shared

arunoda commented 10 years ago

I really can't say much with this info. Can you please create a re-produceable minimal repo. Then I can look it here.

DominikGuzei commented 10 years ago

hmm.. ok it could be that they are not run on the server side – I just tried to console log if Meteor.isServer and nothing happens .. I have to look into that

arunoda commented 10 years ago

ah okay.

DominikGuzei commented 10 years ago

ok the file is definitely served on the server side too. But waitOn or onBeforeAction are never called on server. Is this expected behaviour?

arunoda commented 10 years ago

waitOn needs to get called, others are not.

DominikGuzei commented 10 years ago

Ok, mine never got called!

I changed the router to explicit controller params, and it gets called now:

Router.map ->
  @route Router.ROUTES.DASHBOARD, path: '/', controller: DashboardController

The static fast-render output changed to this:


  if(typeof __init_fast_render == 'function') {
    __init_fast_render("%7B%22collectionData%22:%7B%22projects%22:%5B%5B%5D%5D%7D%7D")
  }

And the fast-render logs changed to this:

DDP_SEND: 
Object {msg: "sub", id: "ZRX79ERbD4Cd5QmaJ", name: "meteor.loginServiceConfiguration", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "login", params: Array[1], id: "1"}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "NDENu4H9NCBoCfdd9", name: "projects", params: Array[0]}
 log.js:7
FAKE_SUB_READY: projects log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1], frGen: true}
 log.js:7
DDP_SEND: 
Object {msg: "connect", version: "pre1", support: Array[1]}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "login", params: Array[1], id: "1"}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "5aSSXL9CLs6bdnLqT", name: "meteor_autoupdate_clientVersions", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "ZRX79ERbD4Cd5QmaJ", name: "meteor.loginServiceConfiguration", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "NDENu4H9NCBoCfdd9", name: "projects", params: Array[0]}
 log.js:7
FAKE_SUB_READY: projects log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1], frGen: true}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "users", id: "zTBnJnGKZ8Zw8wsE3", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "updated", methods: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "meteor_autoupdate_clientVersions", id: "14ff8b135ac283081a6593a22f5e36979c8fe936", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DDP_RECIEVE: 
Object {msg: "added", collection: "projects", id: "HTavSiDGuAcy5Px94", fields: Object}
 log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1]}
 log.js:7
DELETING_SUBSCRIPTION: projects NDENu4H9NCBoCfdd9 log.js:7
REVERTING_BACK_TO_ORIGINAL_DDP_HANDLING: 

However if I run it with DDP_DEFAULT_CONNECTION_URL=http://localhost:3030 meteor it still doesn't work:

GET http://localhost:3030/sockjs/info?cb=tavzyvwwsw net::ERR_CONNECTION_REFUSED sockjs-0.3.4.js:854
DDP_SEND: 
Object {msg: "sub", id: "3wEmwcH2bkH9YFXWv", name: "meteor.loginServiceConfiguration", params: Array[0]}
 log.js:7
DDP_SEND: 
Object {msg: "method", method: "login", params: Array[1], id: "1"}
 log.js:7
DDP_SEND: 
Object {msg: "sub", id: "HR8heAYTioXDrryfT", name: "projects", params: Array[0]}
 log.js:7
FAKE_SUB_READY: projects log.js:7
DDP_RECIEVE: 
Object {msg: "ready", subs: Array[1], frGen: true}
 log.js:7
GET http://localhost:3030/sockjs/info?cb=9r8fmiwxv5 net::ERR_CONNECTION_REFUSED sockjs-0.3.4.js:854
GET http://localhost:3030/sockjs/info?cb=z89c7mp_m5 net::ERR_CONNECTION_REFUSED sockjs-0.3.4.js:854

But no projects are shown …

DominikGuzei commented 10 years ago

Ok I noticed that within my publish function this.userId is at first undefined (when hit by fast-render) and then zTBnJnGKZ8Zw8wsE3 when hit by "normal" DDP request. This is a problem because I filter my projects like this:

Meteor.publish 'projects', ->
  ProjectsCollection = Injector.get('Collections').get('projects')
  console.log this.userId
  ProjectsCollection.find { owner_id: this.userId }, sort: created_at: 1

So fast-render will not get any projects, but normal request do! Is there something I am missing in my setup?

arunoda commented 10 years ago

Okay. there might be issue with 0.8 and how FR does auth. I'll double check.

DominikGuzei commented 10 years ago

Thanks for the fast response! That's amazing support of you :+1:

DominikGuzei commented 10 years ago

I have put together a simple example application that shows this problem: https://github.com/CodeAdventure/meteor-fast-render-userid-failure

Hope this helps you with debugging the problem!

arunoda commented 10 years ago

I fixed this and made a commit to the master. give it a try

DominikGuzei commented 10 years ago

Thank you very much Arunoda! It works as expected now :-) :+1:

arunoda commented 10 years ago

Awesome.


Arunoda Susiripala

@arunoda http://twitter.com/arunoda http://gplus.to/arunodahttps://github.com/arunoda http://www.linkedin.com/in/arunoda

On Fri, Apr 4, 2014 at 2:55 PM, Dominik Guzei notifications@github.comwrote:

Thank you very much Arunoda! It works as expected now :-) [image: :+1:]

— Reply to this email directly or view it on GitHubhttps://github.com/arunoda/meteor-fast-render/issues/38#issuecomment-39546453 .