MCPcopy Index your code
hub / github.com/react/react / pushScriptImpl

Function pushScriptImpl

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js:3841–3893  ·  view source on GitHub ↗
(
  target: Array<Chunk | PrecomputedChunk>,
  props: Object,
)

Source from the content-addressed store, hash-verified

3839}
3840
3841function pushScriptImpl(
3842 target: Array<Chunk | PrecomputedChunk>,
3843 props: Object,
3844): null {
3845 target.push(startChunkForTag('script'));
3846
3847 let children = null;
3848 let innerHTML = null;
3849 for (const propKey in props) {
3850 if (hasOwnProperty.call(props, propKey)) {
3851 const propValue = props[propKey];
3852 if (propValue == null) {
3853 continue;
3854 }
3855 switch (propKey) {
3856 case 'children':
3857 children = propValue;
3858 break;
3859 case 'dangerouslySetInnerHTML':
3860 innerHTML = propValue;
3861 break;
3862 default:
3863 pushAttribute(target, propKey, propValue);
3864 break;
3865 }
3866 }
3867 }
3868 // Scripts never participate as a ViewTransition
3869 target.push(endOfStartTag);
3870
3871 if (__DEV__) {
3872 if (children != null && typeof children !== 'string') {
3873 const descriptiveStatement =
3874 typeof children === 'number'
3875 ? 'a number for children'
3876 : Array.isArray(children)
3877 ? 'an array for children'
3878 : 'something unexpected for children';
3879 console.error(
3880 'A script element was rendered with %s. If script element has children it must be a single string.' +
3881 ' Consider using dangerouslySetInnerHTML or passing a plain string as children.',
3882 descriptiveStatement,
3883 );
3884 }
3885 }
3886
3887 pushInnerHTML(target, innerHTML, children);
3888 if (typeof children === 'string') {
3889 target.push(stringToChunk(escapeEntireInlineScriptContent(children)));
3890 }
3891 target.push(endChunkForTag('script'));
3892 return null;
3893}
3894
3895// This is a fork of pushStartGenericElement because we don't ever want to do
3896// the children as strign optimization on that path when rendering singletons.

Callers 4

createRenderStateFunction · 0.85
pushScriptFunction · 0.85
preinitScriptFunction · 0.85
preinitModuleScriptFunction · 0.85

Calls 8

stringToChunkFunction · 0.90
startChunkForTagFunction · 0.85
pushAttributeFunction · 0.85
pushInnerHTMLFunction · 0.85
endChunkForTagFunction · 0.85
pushMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected