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
[Fiber] Fix to render falsy value as dangerouslySetInnerHTML #8652
[Fiber] Fix to render falsy value as dangerouslySetInnerHTML #8652
Conversation
150dd5e
to
5493a36
Compare
@@ -398,10 +398,11 @@ function updateDOMProperties( | |||
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) { | |||
var nextHtml = nextProp ? nextProp[HTML] : undefined; | |||
var lastHtml = lastProp ? lastProp[HTML] : undefined; | |||
if (nextHtml) { | |||
if (nextHtml || nextHtml === 0 || nextHtml === '') { |
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.
Maybe do a typeof instead? that is what we have done in other places where we need to detect numbers / strings. I am not sure this works with negative values
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.
Thanks! That makes sense. I'll update it.
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.
Fixed it.
5493a36
to
f344590
Compare
@@ -398,10 +398,15 @@ function updateDOMProperties( | |||
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) { | |||
var nextHtml = nextProp ? nextProp[HTML] : undefined; | |||
var lastHtml = lastProp ? lastProp[HTML] : undefined; | |||
if (nextHtml) { | |||
if ( | |||
nextHtml || |
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.
Do we even need this check now?
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 is for consistent with stack reconciler.
Because stack reconciler can render other than string and number.
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.
Ah okay 👍
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.
What about false
? Does Stack render that?
@@ -398,10 +398,15 @@ function updateDOMProperties( | |||
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) { | |||
var nextHtml = nextProp ? nextProp[HTML] : undefined; | |||
var lastHtml = lastProp ? lastProp[HTML] : undefined; | |||
if (nextHtml) { | |||
if ( | |||
nextHtml || |
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.
What about false
? Does Stack render that?
@@ -44,6 +44,28 @@ describe('ReactDOMFiber', () => { | |||
expect(container.textContent).toEqual('10'); | |||
}); | |||
|
|||
it('should render dangerouslySetInnerHTML', () => { |
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.
Let's put this test in ReactDOMComponent-test.js
next to the other dangrouslySetInnerHTML
tests. And give it a more specific name, like "can dangerouslySetInnerHTML
with falsy value."
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.
Thank you for moving the test. Can you remove the ones in this file now? We don't need duplicates because ReactDOMComponent-test
is run in both Stack and Fiber mode.
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.
@acdlite OK, fixed it. I've added the tests using ReactDOM.render
instead of _createContentMarkup
into ReactDOMComponent-test
.
f344590
to
afc208f
Compare
@acdlite Thank you for your review! I've put the tests for falsy values in |
@@ -398,13 +398,10 @@ function updateDOMProperties( | |||
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) { | |||
var nextHtml = nextProp ? nextProp[HTML] : undefined; | |||
var lastHtml = lastProp ? lastProp[HTML] : undefined; | |||
if (nextHtml) { | |||
if (lastHtml) { |
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.
Does this condition still need? It seems to be unnecessary because it is covered by if (lastHtml !== nextHtml)
.
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.
Hmm idk why that branch was there. Seems ok to remove it.
afc208f
to
46d3e81
Compare
This looks good, thank you for fixing! |
Thank you! |
This is to fix a bug which is unable to render falsy values(
0
or''
orfalse
) asdangerouslySetInnerHTML
.