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
Ignore whitespace in the container element when reusing markup #996
Comments
My inclination would be to ignore only text nodes comprised solely of whitespace. |
True, that will work too. |
This is fixed in master (my whitespace PR took care of spaces appearing literally everywhere). |
Sweet, looking forward to the next release then. 😀 |
@syranide I thought your PR only modified jsx -- this is about adopting server-rendered markup. |
Maybe this is clearer. This markup won't be reused: <div class="container">
<div class="component" data-reactid=".r[1wtmm]" data-react-checksum="490228448">...</div>
</div> But this markup will: <div class="container"><div class="component" data-reactid=".r[1wtmm]" data-react-checksum="490228448">...</div></div> The |
@Rowno Aha, yeah my mistake then. Not fixed in master. |
(petehunt says: "We just need to change our use of |
I experimented with a possible fix a little bit. As @spicyj said in #1050 it might be worth it to not ignore prepended non-whitespace text. This gist would be the necessary code if you want to make sure you only ignore text nodes that consist purely of whitespace. But this would get rather more complex if you wanted to make sure you account for the edge case of alternating comment nodes and text nodes until you actually find an element node or a text node with non-whitespace content. Therefore I think it would be much easier to implement @petehunt's proposal and just use In my opinion it makes no sense to do this non-whitespace check, because React doesn't actually make sure there is no appended non-whitespace text neither when re-using DOM nodes that came from the server. |
At the moment, if there's any whitespace around a pre-rendered component inside it's container, the HTML won't be reused. This is because
getReactRootElementInContainer()
usesNode.firstChild
which will return aTEXT_NODE
instead of anELEMENT_NODE
in this case.For example, this HTML won't be reused:
If you want, I can send through a pull request that changes
getReactRootElementInContainer()
to look for the firstELEMENT_NODE
instead of just anyNode
.The text was updated successfully, but these errors were encountered: