diff --git a/packages/react-dom-bindings/src/client/ReactDOMComponent.js b/packages/react-dom-bindings/src/client/ReactDOMComponent.js index e736f2ffb53a8..0caaac1221d35 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMComponent.js +++ b/packages/react-dom-bindings/src/client/ReactDOMComponent.js @@ -55,12 +55,7 @@ import { setValueForStyles, validateShorthandPropertyCollisionInDev, } from './CSSPropertyOperations'; -import { - HTML_NAMESPACE, - MATH_NAMESPACE, - SVG_NAMESPACE, - getIntrinsicNamespace, -} from '../shared/DOMNamespaces'; +import {HTML_NAMESPACE, getIntrinsicNamespace} from '../shared/DOMNamespaces'; import { getPropertyInfo, shouldIgnoreAttribute, @@ -380,15 +375,83 @@ function updateDOMProperties( } } +// creates a script element that won't execute +export function createPotentiallyInlineScriptElement( + ownerDocument: Document, +): Element { + // Create the script via .innerHTML so its "parser-inserted" flag is + // set to true and it does not execute + const div = ownerDocument.createElement('div'); + if (__DEV__) { + if (enableTrustedTypesIntegration && !didWarnScriptTags) { + console.error( + 'Encountered a script tag while rendering React component. ' + + 'Scripts inside React components are never executed when rendering ' + + 'on the client. Consider using template tag instead ' + + '(https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).', + ); + didWarnScriptTags = true; + } + } + div.innerHTML = '