Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[object DocumentFragment] in dom #148

Closed
manuel-schoebel opened this issue Sep 19, 2013 · 14 comments
Closed

[object DocumentFragment] in dom #148

manuel-schoebel opened this issue Sep 19, 2013 · 14 comments

Comments

@manuel-schoebel
Copy link
Contributor

Hey,

i created a very basic example.

https://github.com/DerMambo/iron-router-examples

If i use {{ renderRouter }} i get the string "[object DocumentFragment]" in the body, just before the template that should be rendered.

Am i doing something wrong here?

@cmather
Copy link
Contributor

cmather commented Sep 20, 2013

That should be fine. I'll check the lib/client/helpers.js implementation.

@cmather
Copy link
Contributor

cmather commented Sep 20, 2013

I'm not exactly sure why you're getting a string in the dom. Need to look into that. But make sure you configure the router not to autoRender if you're going to render yourself. The error checking around this should probably be better. Does this work?

Router.configure({
  autoRender: false
});

@manuel-schoebel
Copy link
Contributor Author

autoRender did not helper either. I updated the code in my repo, too.

@tgoorden
Copy link

I'm running into this issue as well. It appears this is due to the fact that Router.render() outputs a DocumentFragment. Handlebars.SafeString doesn't really know what to do with that (it expects a string of HTML instead), so it spits out [object DocumentFragment].

AutoRender doesn't have this problem, because it directly injects the DocumentFragment into the DOM (using appendChild). For this reason, I'm not sure the current approach will work very well, because the DOM is quite likely not ready when/where {{renderRouter}} is called, I'm not sure if you can append DocumentFragments "on the fly".

It seems one of two approaches would be needed:

  1. Convert the DocumentFragment created by Router.render() into a HTML string. DomUtils (Meteor internal package) seems to do stuff like that.
  2. Find some way of inject the DocumentFragment "in place", so in essence where the HandleBars helper is called.

(FYI, this is behavior I'm seeing on Chrome, using the dev branch. There is a chance there are some browser diffs here?)

@tgoorden
Copy link

As a temporary hack, this seems to work for me at the moment:

Add some kind of container to your HTML, anywhere you like really

<div id="#box"></div>

And inject the rendered router when the DOM is ready:

$(document).ready( function() { $("#box").append(Router.render()); });

At first glance, this seems to work.

@tgoorden
Copy link

(Sorry for experimenting semi-live here.)

My hack seems to work until you switch layoutTemplates. Then it starts to break down, probably because the relevant yields become unavailable. I guess one could re-inject the rendered route every time you navigate, but that doesn't sound like a good idea.

@cmather
Copy link
Contributor

cmather commented Sep 26, 2013

I have to go back and revisit to get a better understanding. Spark uses a two phased method for rendering. In the first phase, you get a string of html from each of the components. This string looks like regular html with Spark annotations around it. In the second phase - "materialization" - the annotated html is turned into a dom fragment and returned. The body of the html is automatically turned into an anonymous template. The {{renderRouter}} helper gets called from within this template, and then the template is what gets appended to the dom at the end. This is why it should work. But maybe something is interrupting that process (like a delay in Router.render). My mind is filled with other models at the moment, so if anyone has any additional hints that would be great contribution!

@cmather
Copy link
Contributor

cmather commented Oct 4, 2013

Hey guys, I just pushed a fix for this. Let me know if it works for you now. The problem was that the Router's PageManager (renderLayout) method was calling Spark.render which returns a document fragment. Now renderLayout just uses Spark.isolate which will either return raw html (if not called from within Spark.render) or annotated html if called from within Spark.render.

@dgtlife
Copy link

dgtlife commented Oct 5, 2013

I tested commit 36a155b for manual rendering with layout (just because it was mentioned in Issue #3 above), and it was an improvement, but it appears to be still broken. It ignores the layout and just renders the {{yield}} in the body.

This is how my page layout is structured, and everything works fine with 0.5.4.

<body>
  {{renderRouter}}
</body>

<template name="layout">
  <div id="wrap">
    {{> header}}
    <div id="page" class="container">
      {{> alerts}}
      {{yield}}
    </div>
  </div>
  <div id="footer" class="navbar-fixed-bottom">
    {{> footer}}
  </div>
</template>

With 36a115b, whereas before I just got [object DocumentFragment] in the body, now I just get whatever the {{yield}} template refers to, i.e. no header, no alerts, no footer, no wrap div, no container div ... as if I had this

<body>
{{yield}}
</body>

So looks like you need one more iteration. :-)

@cmather
Copy link
Contributor

cmather commented Oct 5, 2013

Can you show me your router config?

Sent from my iPhone

On Oct 5, 2013, at 4:23 AM, Derek Gransaull notifications@github.com wrote:

I tested commit 36a155b for manual rendering with layout (just because it was mentioned in Issue #3 above), and it was an improvement, but it appears to be still broken. It ignores the layout and just renders the {{yield}} in the body.

This is how my page layout is structured, and everything works fine with 0.5.4.

{{renderRouter}}
{{> header}}
{{> alerts}} {{yield}}
With 36a115b, whereas before I just got [object DocumentFragment] in the body, now I just get whatever the {{yield}} template refers to, i.e. no header, no alerts, no footer, as if I had this {{yield}} So looks like you need one more iteration. :-)


Reply to this email directly or view it on GitHub.

@cmather
Copy link
Contributor

cmather commented Oct 5, 2013

@dgtlife, I just tested this and it's working okay for me. Make sure you're specifying a layoutTemplate in your route or global route options.

Router.configure({
  layoutTemplate: 'layout'
});

It looks like the default layout might be getting used which just has a {{yield}} in it and nothing else.

@dgtlife
Copy link

dgtlife commented Oct 6, 2013

This is my router config; it's been this way since I started using Iron Router.

Router.configure({
  autoRender: false,
  layout: 'layout',
  loadingTemplate: 'loading', // triggered by waitOn
  after: function () {
    Alerts.clearAll();
  }
});

And everything renders fine with 0.5.4.

I notice you have "layoutTemplate" vs my "layout". Is that a new syntax beyond 0.5.4? I'll try that syntax with dev in about an hour and see if that does it.

@cmather
Copy link
Contributor

cmather commented Oct 6, 2013

Yes, and no backward compat yet. Will probably add backward compat before release. You can see History.md for changes in dev with 'breaking changes' highlighted.

Sent from my iPhone

On Oct 5, 2013, at 5:37 PM, Derek Gransaull notifications@github.com wrote:

This is my router config; it's been this way since I started using Iron Router.

Router.configure({
autoRender: false,
layout: 'layout',
loadingTemplate: 'loading', // triggered by waitOn
after: function () {
Alerts.clearAll();
}
});
And everything renders fine with 0.5.4.

I notice you have "layoutTemplate" vs my "layout". Is that a new syntax beyond 0.5.4?


Reply to this email directly or view it on GitHub.

@dgtlife
Copy link

dgtlife commented Oct 6, 2013

And finally, yes, using the "layoutTemplate" syntax with 36a155b works fine. Thanks for doing Iron Router, and for your responsive support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants