-
Notifications
You must be signed in to change notification settings - Fork 414
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
Comments
That should be fine. I'll check the lib/client/helpers.js implementation. |
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 Router.configure({
autoRender: false
}); |
autoRender did not helper either. I updated the code in my repo, too. |
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:
(FYI, this is behavior I'm seeing on Chrome, using the dev branch. There is a chance there are some browser diffs here?) |
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
And inject the rendered router when the DOM is ready:
At first glance, this seems to work. |
(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. |
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! |
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 ( |
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 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
So looks like you need one more iteration. :-) |
Can you show me your router config? Sent from my iPhone
|
@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. |
This is my router config; it's been this way since I started using Iron Router.
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. |
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
|
And finally, yes, using the "layoutTemplate" syntax with 36a155b works fine. Thanks for doing Iron Router, and for your responsive support. |
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?
The text was updated successfully, but these errors were encountered: