Skip to content

Commit d6b59e3

Browse files
committed
Check document.documentMode once
1 parent 52633c8 commit d6b59e3

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/react-dom/src/__tests__/ReactServerRenderingHydration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ describe('ReactDOMServerHydration', () => {
283283

284284
it('should not warn when the style property differs on whitespace or order in IE', () => {
285285
document.documentMode = 11;
286+
jest.resetModules();
287+
React = require('react');
288+
ReactDOM = require('react-dom');
289+
ReactDOMServer = require('react-dom/server');
286290
try {
287291
const element = document.createElement('div');
288292

packages/react-dom/src/client/ReactDOMComponent.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ let warnForTextDifference;
6767
let warnForPropDifference;
6868
let warnForExtraAttributes;
6969
let warnForInvalidEventListener;
70+
let canDiffStyleForHydrationWarning;
7071

7172
let normalizeMarkupForTextOrAttribute;
7273
let normalizeHTML;
@@ -94,6 +95,16 @@ if (__DEV__) {
9495
validateUnknownProperties(type, props, /* canUseEventSystem */ true);
9596
};
9697

98+
// IE 11 parses & normalizes the style attribute as opposed to other
99+
// browsers. It adds spaces and sorts the properties in some
100+
// non-alphabetical order. Handling that would require sorting CSS
101+
// properties in the client & server versions or applying
102+
// `expectedStyle` to a temporary DOM node to read its `style` attribute
103+
// normalized. Since it only affects IE, we're skipping style warnings
104+
// in that browser completely in favor of doing all that work.
105+
// See https://github.com/facebook/react/issues/11807
106+
canDiffStyleForHydrationWarning = !document.documentMode;
107+
97108
// HTML parsing normalizes CR and CRLF to LF.
98109
// It also can turn \u0000 into \uFFFD inside attributes.
99110
// https://www.w3.org/TR/html5/single-page.html#preprocessing-the-input-stream
@@ -1000,15 +1011,7 @@ export function diffHydratedProperties(
10001011
// $FlowFixMe - Should be inferred as not undefined.
10011012
extraAttributeNames.delete(propKey);
10021013

1003-
// IE 11 parses & normalizes the style attribute as opposed to other
1004-
// browsers. It adds spaces and sorts the properties in some
1005-
// non-alphabetical order. Handling that would require sorting CSS
1006-
// properties in the client & server versions or applying
1007-
// `expectedStyle` to a temporary DOM node to read its `style` attribute
1008-
// normalized. Since it only affects IE, we're skipping style warnings
1009-
// in that browser completely in favor of doing all that work.
1010-
// See https://github.com/facebook/react/issues/11807
1011-
if (!document.documentMode) {
1014+
if (canDiffStyleForHydrationWarning) {
10121015
const expectedStyle = CSSPropertyOperations.createDangerousStringForStyles(
10131016
nextProp,
10141017
);

0 commit comments

Comments
 (0)