Skip to content

Commit 5f414e7

Browse files
committed
Removed IE9 workaround. Now we assume Node.setAttribute(NS) stringifies.
1 parent 85f1122 commit 5f414e7

File tree

6 files changed

+4
-106
lines changed

6 files changed

+4
-106
lines changed

fixtures/dom/src/components/Header.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ class Header extends React.Component {
8989
<option value="/selection-events">Selection Events</option>
9090
<option value="/suspense">Suspense</option>
9191
<option value="/form-state">Form State</option>
92-
<option value="/attribute-stringification">
93-
Attribute Stringification
94-
</option>
9592
</select>
9693
</label>
9794
<label htmlFor="global_version">

fixtures/dom/src/components/fixtures/attribute-stringification/AttributeStringificationTestCase.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

fixtures/dom/src/components/fixtures/attribute-stringification/index.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

fixtures/dom/src/polyfills.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'core-js/es6/symbol';
22
import 'core-js/es6/promise';
33
import 'core-js/es6/set';
44
import 'core-js/es6/map';
5-
import 'core-js/features/array/fill';
65

76
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
87
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

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

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@ import {isOpaqueHydratingObject} from './ReactDOMHostConfig';
2121

2222
import type {PropertyInfo} from '../shared/DOMProperty';
2323

24-
/**
25-
* Cached result of detectStringification() function.
26-
* Should become true in all environments but IE<=9.
27-
*/
28-
let setAttributeCanStringify = undefined;
29-
30-
/**
31-
* Detect if Element.setAttribute stringifies attribute values.
32-
* Should return true for all environments but IE <= 9.
33-
* @param {DOMElement} node
34-
*/
35-
function detectStringification(node: Element) {
36-
const obj: any = {
37-
toString: () => 'foo',
38-
};
39-
const attrName = 'title';
40-
const el = node.ownerDocument.createElement('p');
41-
el.setAttribute(attrName, obj);
42-
return el.getAttribute(attrName) === 'foo';
43-
}
44-
4524
/**
4625
* Get the value for a property on a node. Only used in DEV for SSR validation.
4726
* The "expected" argument is used as a hint of what the expected value is.
@@ -164,20 +143,15 @@ export function setValueForProperty(
164143
if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
165144
value = null;
166145
}
167-
if (setAttributeCanStringify === undefined) {
168-
setAttributeCanStringify = detectStringification(node);
169-
}
170146
// If the prop isn't in the special list, treat it as a simple attribute.
171147
if (isCustomComponentTag || propertyInfo === null) {
172148
if (isAttributeNameSafe(name)) {
173149
const attributeName = name;
174150
if (value === null) {
175151
node.removeAttribute(attributeName);
176152
} else {
177-
node.setAttribute(
178-
attributeName,
179-
setAttributeCanStringify ? (value: any) : '' + (value: any),
180-
);
153+
// Node.setAttribute(NS) stringifies the value implicitly in all browsers apart from IE <= 9.
154+
node.setAttribute(attributeName, (value: any));
181155
}
182156
}
183157
return;
@@ -207,13 +181,8 @@ export function setValueForProperty(
207181
// and we won't require Trusted Type here.
208182
attributeValue = '';
209183
} else {
210-
if (setAttributeCanStringify) {
211-
attributeValue = (value: any);
212-
} else {
213-
// As `setAttribute` does not stringify the value itself.
214-
// ('' + value) makes it output the correct toString()-value.
215-
attributeValue = '' + (value: any);
216-
}
184+
// Node.setAttribute(NS) stringifies the value implicitly in all browsers apart from IE <= 9.
185+
attributeValue = (value: any);
217186
if (propertyInfo.sanitizeURL) {
218187
attributeValue = sanitizeURL(attributeValue);
219188
}

packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ describe('when Trusted Types are available in global object', () => {
6161
};
6262
fakeTTObjects.add(ttObject1);
6363
fakeTTObjects.add(ttObject2);
64-
// Run setAttributeCanStringify detection first to simplify counting
65-
// setAttribute calls later.
66-
ReactDOM.render(<div foo="bar" />, container);
6764
});
6865

6966
afterEach(() => {

0 commit comments

Comments
 (0)