-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
fix: skip dangerouslySetInnerHtml hydration warning if it's undefined #18676
Merged
gaearon
merged 6 commits into
facebook:master
from
eps1lon:fix/dangerous-hydration-warning
Apr 20, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b14d38a
test: Add failing case for dangerouslySetInnerHtml=undefined
eps1lon 47c0e9e
fix: skip dangerouslySetInnerHtml warning if it's undefined
eps1lon b72da4e
test: add similar test that should trigger the warning
eps1lon 5badbd9
chore: Remove redundant nullish check
eps1lon 63387c2
Poke yarn_test_www_variant which timed out
eps1lon 5c05857
test: Add smaller test for innerHTML=string to innerHTML=undefined
eps1lon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So.. what if
nextHtml
isnull
orundefined
on the client, but it was notnull
on the server? Wouldn't this miss 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.
I had the exact same question. This is pretty similar to the second test I added (https://github.com/facebook/react/pull/18676/files#diff-ab371863932cd2e8f0ba14ff2eaab380R568). I can change it not render anything on the client or add a new one that goes from
{ __html: "server" }
toundefined
.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.
Adding new one sounds good.
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'm just asking how it works.
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 didn't read much of the surrounding code and relied on the tests doing what I expected so I can't tell you how it works.
Maybe I should convert it to a table and
it.each
so that it's more visible how the props change between client and server? The tests are mostly setup.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.
We prefer explicitly written tests to
it.each
. Don't worry about duplication.I think we need to figure out how it works before we can be comfortable merging this. :-)
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.
Sure thing. Let me trace this for each test case. Maybe this clears this up.
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.
When tracing the code I wasn't sure if this might result in a loss of component stacks so I added these to the test to make sure.
It looks like the reconciler is going through all the instances that aren't hydrated and deletes them:
react/packages/react-reconciler/src/ReactFiberHydrationContext.old.js
Line 462 in dc630d3
The host config is then responsible for warning about the deletion of hydrateable text/elements:
react/packages/react-dom/src/client/ReactDOMHostConfig.js
Line 957 in 58c895e
So it's no longer warning about a mismatch in
dangerouslySetInnerHTML
but rather that the resulting html mismatches.It seems like both approaches do not create a helpful error message. In the version on
master
it displays the wrong content ofdangerouslySetInnerHTML
thinking that it's<p>server</p>
while this content came from thechildren
prop. In the version on this PR we no longer see thatdangerouslySetInnerHTML
was part of the issue.