@samitouri / QOS-React / commits / e5db5302ac

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

Dan Abramov committed Oct 10, 2017 at 19:35 UTC e5db5302ac76e688ca044177d199435272c3ade1
2 files changed +11 -7
fixtures/ssr/src/components/Chrome.js
+5
@@ -15,6 +15,11 @@ export default class Chrome extends Component {
15 <title>{this.props.title}</title>
16 </head>
17 <body>
18 + <noscript
19 + dangerouslySetInnerHTML={{
20 + __html: `<b>Enable JavaScript to run this app.</b>`,
21 + }}
22 + />
23 {this.props.children}
24 <script
25 dangerouslySetInnerHTML={{
src/renderers/dom/fiber/ReactDOMFiberComponent.js
+6 -7
@@ -164,17 +164,16 @@ if (__DEV__) {
164 );
165 };
166
167 - var testDocument;
167 // Parse the HTML and read it back to normalize the HTML string so that it
168 // can be used for comparison.
169 var normalizeHTML = function(parent: Element, html: string) {
171 - if (!testDocument) {
172 - // The title argument is required in IE11 so we pass an empty string.
173 - testDocument = document.implementation.createHTMLDocument('');
174 - }
170 + // We could have created a separate document here to avoid
171 + // re-initializing custom elements if they exist. But this breaks
172 + // how <noscript> is being handled. So we use the same document.
173 + // See the discussion in https://github.com/facebook/react/pull/11157.
174 var testElement = parent.namespaceURI === HTML_NAMESPACE
176 - ? testDocument.createElement(parent.tagName)
177 - : testDocument.createElementNS(
175 + ? parent.ownerDocument.createElement(parent.tagName)
176 + : parent.ownerDocument.createElementNS(
177 (parent.namespaceURI: any),
178 parent.tagName,
179 );