martyjs / marty

A Javascript library for state management in React applications
http://martyjs.org
MIT License
1.09k stars 77 forks source link

Marty.renderToString results in React warning #288

Closed duro closed 9 years ago

duro commented 9 years ago

I am setting up a Marty isomorphic app, and so far I have everything rendering properly from the server. However when I open up the console in my browser, I have the following warning:

Warning: render(): Target node has markup rendered by React, but there are unrelated nodes as well. This is most commonly caused by white-space inserted around server-rendered markup.

I think that what is causing this is the <script> tag that Marty injects at the end of the rendered HTML that is used for dehydration/rehaydration.

Is there a way to avoid this?

bishtawi commented 9 years ago

I see the same thing.

jackcallister commented 9 years ago

It's definitely the script which injects the __marty variable. A possible adhoc solutions would be to split the script out from the react html and leave it up to the user to inject it into their template.

Marty.renderToString({
    type: Component,
    context: context
}).then(function (render) {
    res.render('index', { html: render.html, marty: render.marty });
});
duro commented 9 years ago

I like @jarsbe's solution

jhollingworth commented 9 years ago

Sorry for the delay getting to this. I've just released marty v0.9.17 which adds htmlBody and htmlState to the render result allowing you to do @jarsbe's solution. I've just released marty-express v0.4.0 which takes advantage of these new variables.