Skip to content

Commit

Permalink
Removed IE9 workaround. Now we assume Node.setAttribute(NS) stringifies.
Browse files Browse the repository at this point in the history
  • Loading branch information
koto committed Jun 15, 2021
1 parent 85f1122 commit 23fdae0
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 103 deletions.
3 changes: 0 additions & 3 deletions fixtures/dom/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ class Header extends React.Component {
<option value="/selection-events">Selection Events</option>
<option value="/suspense">Suspense</option>
<option value="/form-state">Form State</option>
<option value="/attribute-stringification">
Attribute Stringification
</option>
</select>
</label>
<label htmlFor="global_version">
Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion fixtures/dom/src/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'core-js/es6/symbol';
import 'core-js/es6/promise';
import 'core-js/es6/set';
import 'core-js/es6/map';
import 'core-js/features/array/fill';

// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
Expand Down
36 changes: 4 additions & 32 deletions packages/react-dom/src/client/DOMPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,6 @@ import {isOpaqueHydratingObject} from './ReactDOMHostConfig';

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

/**
* Cached result of detectStringification() function.
* Should become true in all environments but IE<=9.
*/
let setAttributeCanStringify = undefined;

/**
* Detect if Element.setAttribute stringifies attribute values.
* Should return true for all environments but IE <= 9.
* @param {DOMElement} node
*/
function detectStringification(node: Element) {
const obj: any = {
toString: () => 'foo',
};
const attrName = 'title';
const el = node.ownerDocument.createElement('p');
el.setAttribute(attrName, obj);
return el.getAttribute(attrName) === 'foo';
}

/**
* Get the value for a property on a node. Only used in DEV for SSR validation.
* The "expected" argument is used as a hint of what the expected value is.
Expand Down Expand Up @@ -164,19 +143,17 @@ export function setValueForProperty(
if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
value = null;
}
if (setAttributeCanStringify === undefined) {
setAttributeCanStringify = detectStringification(node);
}
// If the prop isn't in the special list, treat it as a simple attribute.
if (isCustomComponentTag || propertyInfo === null) {
if (isAttributeNameSafe(name)) {
const attributeName = name;
if (value === null) {
node.removeAttribute(attributeName);
} else {
// Node.setAttribute(NS) stringifies the value implicitly in all browsers apart from IE <= 9.
node.setAttribute(
attributeName,
setAttributeCanStringify ? (value: any) : '' + (value: any),
(value: any),
);
}
}
Expand Down Expand Up @@ -207,13 +184,8 @@ export function setValueForProperty(
// and we won't require Trusted Type here.
attributeValue = '';
} else {
if (setAttributeCanStringify) {
attributeValue = (value: any);
} else {
// As `setAttribute` does not stringify the value itself.
// ('' + value) makes it output the correct toString()-value.
attributeValue = '' + (value: any);
}
// Node.setAttribute(NS) stringifies the value implicitly in all browsers apart from IE <= 9.
attributeValue = (value: any);
if (propertyInfo.sanitizeURL) {
attributeValue = sanitizeURL(attributeValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ describe('when Trusted Types are available in global object', () => {
};
fakeTTObjects.add(ttObject1);
fakeTTObjects.add(ttObject2);
// Run setAttributeCanStringify detection first to simplify counting
// setAttribute calls later.
ReactDOM.render(<div foo="bar" />, container);
});

afterEach(() => {
Expand Down

0 comments on commit 23fdae0

Please sign in to comment.