diff --git a/packages/react-dom/src/client/ToStringValue.js b/packages/react-dom/src/client/ToStringValue.js index cf4a173e1399d..4844e0685dc41 100644 --- a/packages/react-dom/src/client/ToStringValue.js +++ b/packages/react-dom/src/client/ToStringValue.js @@ -53,15 +53,14 @@ export opaque type TrustedValue: {toString(): string, valueOf(): string} = { */ export let toStringOrTrustedType: any => string | TrustedValue = toString; if (enableTrustedTypesIntegration && typeof trustedTypes !== 'undefined') { - const isHTML = trustedTypes.isHTML; - const isScript = trustedTypes.isScript; - const isScriptURL = trustedTypes.isScriptURL; - // TrustedURLs are deprecated and will be removed soon: https://github.com/WICG/trusted-types/pull/204 - const isURL = trustedTypes.isURL ? trustedTypes.isURL : value => false; toStringOrTrustedType = value => { if ( typeof value === 'object' && - (isHTML(value) || isScript(value) || isScriptURL(value) || isURL(value)) + (trustedTypes.isHTML(value) || + trustedTypes.isScript(value) || + trustedTypes.isScriptURL(value) || + /* TrustedURLs are deprecated and will be removed soon: https://github.com/WICG/trusted-types/pull/204 */ + (trustedTypes.isURL && trustedTypes.isURL(value))) ) { // Pass Trusted Types through. return value; diff --git a/packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js b/packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js index b3511b43dc3ab..53f5759157cc6 100644 --- a/packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js +++ b/packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js @@ -22,7 +22,12 @@ describe('when Trusted Types are available in global object', () => { container = document.createElement('div'); const fakeTTObjects = new Set(); window.trustedTypes = { - isHTML: value => fakeTTObjects.has(value), + isHTML: function(value) { + if (this !== window.trustedTypes) { + throw new Error(this); + } + return fakeTTObjects.has(value); + }, isScript: () => false, isScriptURL: () => false, };