-
Notifications
You must be signed in to change notification settings - Fork 48.8k
Refactor shouldSetTextContent & Add tests (#11789) #11792
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -659,14 +659,36 @@ const DOMRenderer = ReactFiberReconciler({ | |
}, | ||
|
||
shouldSetTextContent(type: string, props: Props): boolean { | ||
return ( | ||
type === 'textarea' || | ||
if (type === 'textarea') { | ||
return true; | ||
} | ||
|
||
if ( | ||
typeof props.children === 'string' || | ||
typeof props.children === 'number' || | ||
(typeof props.dangerouslySetInnerHTML === 'object' && | ||
props.dangerouslySetInnerHTML !== null && | ||
typeof props.dangerouslySetInnerHTML.__html === 'string') | ||
); | ||
typeof props.children === 'number' | ||
) { | ||
return true; | ||
} | ||
|
||
if ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall: we are reading |
||
typeof props.dangerouslySetInnerHTML === 'object' && | ||
props.dangerouslySetInnerHTML !== null | ||
) { | ||
if (typeof props.dangerouslySetInnerHTML.__html === 'string') { | ||
return true; | ||
} | ||
|
||
// Or allow any type of object through - this is to allow React to render | ||
// the `toString` method of objects. (#11792) | ||
if ( | ||
typeof props.dangerouslySetInnerHTML.__html === 'object' && | ||
props.dangerouslySetInnerHTML.__html !== 'null' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we comparing to a string literal here? Is this a bug? In that case it means we're missing a test that would have caught it. |
||
) { | ||
return true; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it strings and objects specifically that are allowed? What if What did React 15 do in this case? Can you point to similar logic there so we can compare the behavior? |
||
|
||
return false; | ||
}, | ||
|
||
shouldDeprioritizeSubtree(type: string, props: Props): boolean { | ||
|
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.
Can we add some tests to
ReactDOMServerIntegration*
suite instead? They will test all possible combinations and verify those match between client-only/server-only/hydration scenarios.