-
Notifications
You must be signed in to change notification settings - Fork 48.6k
Improve warning in react mount #4324
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
Conversation
c567947
to
902b607
Compare
Your unit test passes even without your changes to ReactMount :/. |
Man. I definitely checked that at one point ;) Let me see what happened. |
There we go. |
normalizedMarkup = normalizer.innerHTML; | ||
} else { | ||
normalizer = document.createElement('iframe'); | ||
document.body.appendChild(normalizer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should not be appending a child to the body here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to, but unfortunately iframes only get a valid contentDocument when in the DOM. I've addressed this by immediately removing it from the DOM.
var difference = ' (client) ' + | ||
markup.substring(diffIndex - 20, diffIndex + 20) + | ||
normalizedMarkup.substring(diffIndex - 20, diffIndex + 20) + | ||
'\n (server) ' + rootMarkup.substring(diffIndex - 20, diffIndex + 20); | ||
|
||
invariant( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invariant shouldn't be in devmode block. @zpao should this even be an invariant? Seems like this could just be a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the devmode block ends on line 901.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't in a dev block and yes it should be an invariant. The message makes it pretty clear that React probably breaks when rendering to the document element with content that doesn't checksum.
We have a dev block lower for the warning. We could perhaps have a more concise difference there.
Ok, all looks reasonable to me. Thanks @drd! |
Is there any chance that this fix could be applied to the 0.13.x branch as well? I'm currently running a custom version of React which is just 0.13.3 with this pull request applied on top. |
@leolannenmaki We don't generally backport anything except critical fixes. React 0.14 should be out soon :). In the mean time, you can develop/test against master, or use one of the prebuilt packages mentioned in #4311, or do what you're already doing now. |
@jimfb ok, thanks. Looking forward to 0.14 👍 |
While I was debugging a problem reusing server-rendered markup, I was thrown off the track for a while because React was telling me there were differences in various entity encodings and attribute representations between the server- and client-rendered markup. For instance, the server markup would contain
while the client would contain a literal\u00a0
character. Also, empty attributes on the client would be rendered asattribute
whereas the server markup would showattribute=""
. After finally realizing that the real problem was in fact a different string being rendered on server vs client, I came up with this method to present more useful information when this situation arises.