Skip to content

Commit e5db530

Browse files
authored
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 27a4250. * Always use parent.ownerDocument
1 parent f42dfcd commit e5db530

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

fixtures/ssr/src/components/Chrome.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export default class Chrome extends Component {
1515
<title>{this.props.title}</title>
1616
</head>
1717
<body>
18+
<noscript
19+
dangerouslySetInnerHTML={{
20+
__html: `<b>Enable JavaScript to run this app.</b>`,
21+
}}
22+
/>
1823
{this.props.children}
1924
<script
2025
dangerouslySetInnerHTML={{

src/renderers/dom/fiber/ReactDOMFiberComponent.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,16 @@ if (__DEV__) {
164164
);
165165
};
166166

167-
var testDocument;
168167
// Parse the HTML and read it back to normalize the HTML string so that it
169168
// can be used for comparison.
170169
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.
175174
var testElement = parent.namespaceURI === HTML_NAMESPACE
176-
? testDocument.createElement(parent.tagName)
177-
: testDocument.createElementNS(
175+
? parent.ownerDocument.createElement(parent.tagName)
176+
: parent.ownerDocument.createElementNS(
178177
(parent.namespaceURI: any),
179178
parent.tagName,
180179
);

0 commit comments

Comments
 (0)