mizzao / meteor-sharejs

Meteor smart package for transparently adding ShareJS editors to an app
MIT License
225 stars 53 forks source link

Editor always "Loading...", sharejs.open callback returning undefined @data and @_editor #18

Closed swese44 closed 10 years ago

swese44 commented 10 years ago

I'm on the latest version of Meteor and meteor-sharejs and running into a strange issue. When browsing to a document page through iron-router/push state navigation (clicking on any links or hitting the back button to land on a "room" with Ace sharejs editor) the document will always say "Loading...". If a re-render is triggered it gets updated, but otherwise remains "Loading...". You can see the issue by creating a new room on SeeMeCode.com, and by going Home then clicking the browser Back button. Refreshing the entire page works, and setting a new question or changing the programming language fixes it.

I've looked into sharejs-client.coffee, @_editor and @data are both undefined in the sharejs.open call when this happens. I haven't found a workaround yet.

mizzao commented 10 years ago

I think this can happen if a re-render is triggered too quickly immediately after another one. Do you see any errors in the browser console?

swese44 commented 10 years ago

No errors in the console. Is there a way we can delay the render, or delay the sharejs.open call until the data is ready?

Sent from my iPhone

On Jul 3, 2014, at 8:17 AM, Andrew Mao notifications@github.com wrote:

I think this can happen if a re-render is triggered too quickly immediately after another one. Do you see any errors in the browser console?

— Reply to this email directly or view it on GitHub.

mizzao commented 10 years ago

Well, you can certainly do that with the onBeforeAction hook in IR, or just don't render the ShareJS template until it's ready by using {{#if}} blocks in templates, etc.

swese44 commented 10 years ago

I've gotten this working by conditionally rendering the editor based on a Session variable. The Session variable is set to true after a timeout of 500ms in the rendered callback and then the editor is rendered. Not very elegant but it seems to consistently work.

Is there a better way to know when the editor is ready instead of just waiting some extra time? Thanks!

mizzao commented 10 years ago

Is there any chance you are passing a variable (i.e. helper or changing data context value) rather than a constant to any argument of {{> shareJSAce ...}} other than docId? That could break things for the reasons I mentioned above, especially when the value changes right after the template renders.

swese44 commented 10 years ago

{{> sharejsAce docid=_id callback=configCallback id="editor"}}

Just the callback function and docid.

mizzao commented 10 years ago

@swese44 can you try the blaze-refactor branch on Meteor 0.8.3-rc and tell me if you still see this problem?

swese44 commented 10 years ago

What's the command for updating to a release candidate version? I've tried a few variations but I'm getting unknown release

meteor update --release 0.8.3-rc
meteor update --release 0.8.3rc
meteor update --release 0.8.3
swese44 commented 10 years ago

Oh got it: meteor update --release 0.8.3-rc0

I'll try this out and get back to you. Thanks!

swese44 commented 10 years ago

I see they're up to rc5, updating meteor update --release 0.8.3-rc5

swese44 commented 10 years ago

Getting a client-side error from Iron Router that prevents anything from rendering in the browser. I'm not sure if this is coming from Iron Router or from another component.

Exception in defer callback: Error: No uiManager configured on Router
    at Utils.extend.autoRender (http://localhost:3000/packages/iron-router.js?c090b9c4783dd280cc66c81227101bdc3aeb6517:1583:13)
    at http://localhost:3000/packages/iron-router.js?c090b9c4783dd280cc66c81227101bdc3aeb6517:1428:16
    at _.extend.withValue (http://localhost:3000/packages/meteor.js?7a66be7a03504cd2c18dd47b699e6233b60675ed:793:17)
    at http://localhost:3000/packages/meteor.js?7a66be7a03504cd2c18dd47b699e6233b60675ed:382:45
    at Object.<anonymous> (http://localhost:3000/packages/meteor.js?7a66be7a03504cd2c18dd47b699e6233b60675ed:821:22)
    at onGlobalMessage (http://localhost:3000/packages/meteor.js?7a66be7a03504cd2c18dd47b699e6233b60675ed:319:23)
mizzao commented 10 years ago

You need to use the devel branch of iron router which has been updated for new APIs in 0.8.3. On Jul 26, 2014 3:53 PM, "P.J. Swesey" notifications@github.com wrote:

Getting a client-side error from Iron Router that prevents anything from rendering in the browser. I'm not sure if this is coming from Iron Router or from another component.

Exception in defer callback: Error: No uiManager configured on Router at Utils.extend.autoRender (http://localhost:3000/packages/iron-router.js?c090b9c4783dd280cc66c81227101bdc3aeb6517:1583:13) at http://localhost:3000/packages/iron-router.js?c090b9c4783dd280cc66c81227101bdc3aeb6517:1428:16 at _.extend.withValue (http://localhost:3000/packages/meteor.js?7a66be7a03504cd2c18dd47b699e6233b60675ed:793:17) at http://localhost:3000/packages/meteor.js?7a66be7a03504cd2c18dd47b699e6233b60675ed:382:45 at Object. (http://localhost:3000/packages/meteor.js?7a66be7a03504cd2c18dd47b699e6233b60675ed:821:22) at onGlobalMessage (http://localhost:3000/packages/meteor.js?7a66be7a03504cd2c18dd47b699e6233b60675ed:319:23)

— Reply to this email directly or view it on GitHub https://github.com/mizzao/meteor-sharejs/issues/18#issuecomment-50246687 .

swese44 commented 10 years ago

Hmm, still have the same error. Must be another package but the error is not specific. Here is my smart.json file:

{
  "packages": {
    "bootstrap-3": {},
    "iron-router": {
        "git": "https://github.com/EventedMind/iron-router.git",
        "branch": "devel"
    },
    "bootstrap-errors": {},
    "streams": {},
    "profile-online": {},
    "iron-router-progress": {},
    "accounts-guest": {},
    "GAnalytics": {},
    "spin": {},
    "accounts-ui-bootstrap-3": {},
    "sharejs": {
        "git": "https://github.com/mizzao/meteor-sharejs.git",
        "branch": "blaze-refactor"
    },
    "sass": {}
  }
}
mizzao commented 10 years ago

Make sure you mrt update . to pull in new versions of IR dependent packages. On Jul 26, 2014 4:01 PM, "P.J. Swesey" notifications@github.com wrote:

Hmm, still have the same error. Must be another package but the error is not specific. Here is my smart.json file:

{ "packages": { "bootstrap-3": {}, "iron-router": { "git": "https://github.com/EventedMind/iron-router.git", "branch": "devel" }, "bootstrap-errors": {}, "streams": {}, "profile-online": {}, "iron-router-progress": {}, "accounts-guest": {}, "GAnalytics": {}, "spin": {}, "accounts-ui-bootstrap-3": {}, "sharejs": { "git": "https://github.com/mizzao/meteor-sharejs.git", "branch": "blaze-refactor" }, "sass": {} } }

— Reply to this email directly or view it on GitHub https://github.com/mizzao/meteor-sharejs/issues/18#issuecomment-50246884 .

swese44 commented 10 years ago

Yep I did

swese44 commented 10 years ago

Wait after an additional mrt update it's rendering again :) I'll remove my setTimeout() hacks and let you know

swese44 commented 10 years ago

Hmm nope, still gets stuck with "Loading..."

FYI this is my hacky workaround at the moment, it continuously polls until the editor has loaded:

{{#if showEditor}}
        {{> sharejsAce docid=_id callback=configCallback id="editor"}}
      {{else}}
        <div id="editor-placeholder"></div>
      {{/if}}
// HACK FOR EDITOR LOADING ISSUE =========================
  // Initially render the editor after a quick delay
  Session.set('showEditor', false);
  window.setTimeout(function() {
    Session.set('showEditor', true);
  }, 250);

  // Continue checking every second, keep reloading until "Loading..." goes away :(
  var interval = window.setInterval(function() {

    if ($('.ace_line').text() === 'Loading...') {
      Session.set('showEditor', false);
      window.setTimeout(function() {
        Session.set('showEditor', true);
      }, 10);

    } else {
      window.clearInterval(interval);
    }

  }, 1000);
  // END EDITOR HACK =======================================
mizzao commented 10 years ago

Can you try making the minimal demo app that demonstrates this Loading... behavior? I think I've seen this before too, but it doesn't seem to occur in the demo app I've made or the way I use the app. Do you think you could replicate this by loading the editor the same way you do in your app?

I'm guessing the original post in https://github.com/mizzao/meteor-sharejs/issues/16#issue-35458386 was also referring to this issue.

mizzao commented 10 years ago

Please post a new message in this issue if you are still having a problem.