[Fiber] Fix to render falsy value as dangerouslySetInnerHTML#8652
[Fiber] Fix to render falsy value as dangerouslySetInnerHTML#8652gaearon merged 2 commits intofacebook:masterfrom
Conversation
150dd5e to
5493a36
Compare
| 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.
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.
Thanks! That makes sense. I'll update it.
5493a36 to
f344590
Compare
| var lastHtml = lastProp ? lastProp[HTML] : undefined; | ||
| if (nextHtml) { | ||
| if ( | ||
| nextHtml || |
There was a problem hiding this comment.
Do we even need this check now?
There was a problem hiding this comment.
This is for consistent with stack reconciler.
Because stack reconciler can render other than string and number.
There was a problem hiding this comment.
What about false? Does Stack render that?
| var lastHtml = lastProp ? lastProp[HTML] : undefined; | ||
| if (nextHtml) { | ||
| if ( | ||
| nextHtml || |
There was a problem hiding this comment.
What about false? Does Stack render that?
| expect(container.textContent).toEqual('10'); | ||
| }); | ||
|
|
||
| it('should render dangerouslySetInnerHTML', () => { |
There was a problem hiding this comment.
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.
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.
@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 |
| var nextHtml = nextProp ? nextProp[HTML] : undefined; | ||
| var lastHtml = lastProp ? lastProp[HTML] : undefined; | ||
| if (nextHtml) { | ||
| if (lastHtml) { |
There was a problem hiding this comment.
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.
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(
0or''orfalse) asdangerouslySetInnerHTML.