Fix false positive <noscript> rehydration text difference warning in React 16 (#11157)

* Add <noscript> with HTML in it to SSR fixture

* Wrap <noscript> into a <div> to get its "client HTML"

* Revert "Wrap <noscript> into a <div> to get its "client HTML""

This reverts commit 27a42503e2790a0d5cf0b90451a664fc6ab9d862.

* Always use parent.ownerDocument
This commit is contained in:
Dan Abramov 2017-10-10 19:35:43 +01:00 committed by GitHub
parent f42dfcdb94
commit e5db5302ac
2 changed files with 11 additions and 7 deletions

View File

@ -15,6 +15,11 @@ export default class Chrome extends Component {
<title>{this.props.title}</title> <title>{this.props.title}</title>
</head> </head>
<body> <body>
<noscript
dangerouslySetInnerHTML={{
__html: `<b>Enable JavaScript to run this app.</b>`,
}}
/>
{this.props.children} {this.props.children}
<script <script
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{

View File

@ -164,17 +164,16 @@ if (__DEV__) {
); );
}; };
var testDocument;
// Parse the HTML and read it back to normalize the HTML string so that it // Parse the HTML and read it back to normalize the HTML string so that it
// can be used for comparison. // can be used for comparison.
var normalizeHTML = function(parent: Element, html: string) { var normalizeHTML = function(parent: Element, html: string) {
if (!testDocument) { // We could have created a separate document here to avoid
// The title argument is required in IE11 so we pass an empty string. // re-initializing custom elements if they exist. But this breaks
testDocument = document.implementation.createHTMLDocument(''); // how <noscript> is being handled. So we use the same document.
} // See the discussion in https://github.com/facebook/react/pull/11157.
var testElement = parent.namespaceURI === HTML_NAMESPACE var testElement = parent.namespaceURI === HTML_NAMESPACE
? testDocument.createElement(parent.tagName) ? parent.ownerDocument.createElement(parent.tagName)
: testDocument.createElementNS( : parent.ownerDocument.createElementNS(
(parent.namespaceURI: any), (parent.namespaceURI: any),
parent.tagName, parent.tagName,
); );