Skip to content

Commit 5356ecb

Browse files
committed
Remove special casing of toString values when enableTrustedTypesIntegration
As far as I can tell, we only toString in user space because of IE8/9. We don't really support IE8/9 anymore and by the time this flag is on, we should be able to deprecate it. Unless this is also an issue in IE11. I haven't tested yet.
1 parent 9b1d183 commit 5356ecb

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import {
1616
OVERLOADED_BOOLEAN,
1717
} from '../shared/DOMProperty';
1818
import sanitizeURL from '../shared/sanitizeURL';
19-
import {toStringOrTrustedType} from './ToStringValue';
20-
import {disableJavaScriptURLs} from 'shared/ReactFeatureFlags';
19+
import {
20+
disableJavaScriptURLs,
21+
enableTrustedTypesIntegration,
22+
} from 'shared/ReactFeatureFlags';
2123
import {setAttribute, setAttributeNS} from './setAttribute';
2224

2325
import type {PropertyInfo} from '../shared/DOMProperty';
@@ -144,7 +146,11 @@ export function setValueForProperty(
144146
if (value === null) {
145147
node.removeAttribute(attributeName);
146148
} else {
147-
setAttribute(node, attributeName, toStringOrTrustedType(value));
149+
setAttribute(
150+
node,
151+
attributeName,
152+
enableTrustedTypesIntegration ? value : value + '',
153+
);
148154
}
149155
}
150156
return;
@@ -176,7 +182,9 @@ export function setValueForProperty(
176182
} else {
177183
// `setAttribute` with objects becomes only `[object]` in IE8/9,
178184
// ('' + value) makes it output the correct toString()-value.
179-
attributeValue = toStringOrTrustedType(value);
185+
if (!enableTrustedTypesIntegration) {
186+
attributeValue = value + '';
187+
}
180188
if (propertyInfo.sanitizeURL) {
181189
sanitizeURL(attributeValue.toString());
182190
}

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* @flow
88
*/
99

10-
import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
11-
1210
export opaque type ToStringValue =
1311
| boolean
1412
| number
@@ -43,28 +41,3 @@ export opaque type TrustedValue: {toString(): string, valueOf(): string} = {
4341
toString(): string,
4442
valueOf(): string,
4543
};
46-
47-
/**
48-
* We allow passing objects with toString method as element attributes or in dangerouslySetInnerHTML
49-
* and we do validations that the value is safe. Once we do validation we want to use the validated
50-
* value instead of the object (because object.toString may return something else on next call).
51-
*
52-
* If application uses Trusted Types we don't stringify trusted values, but preserve them as objects.
53-
*/
54-
export let toStringOrTrustedType: any => string | TrustedValue = toString;
55-
if (enableTrustedTypesIntegration && typeof trustedTypes !== 'undefined') {
56-
toStringOrTrustedType = value => {
57-
if (
58-
typeof value === 'object' &&
59-
(trustedTypes.isHTML(value) ||
60-
trustedTypes.isScript(value) ||
61-
trustedTypes.isScriptURL(value) ||
62-
/* TrustedURLs are deprecated and will be removed soon: https://github.com/WICG/trusted-types/pull/204 */
63-
(trustedTypes.isURL && trustedTypes.isURL(value)))
64-
) {
65-
// Pass Trusted Types through.
66-
return value;
67-
}
68-
return toString(value);
69-
};
70-
}

0 commit comments

Comments
 (0)