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

Function pushScript

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js:3761–3839  ·  view source on GitHub ↗
(
  target: Array<Chunk | PrecomputedChunk>,
  props: Object,
  resumableState: ResumableState,
  renderState: RenderState,
  textEmbedded: boolean,
  formatContext: FormatContext,
)

Source from the content-addressed store, hash-verified

3759}
3760
3761function pushScript(
3762 target: Array<Chunk | PrecomputedChunk>,
3763 props: Object,
3764 resumableState: ResumableState,
3765 renderState: RenderState,
3766 textEmbedded: boolean,
3767 formatContext: FormatContext,
3768): null {
3769 const noscriptTagInScope = formatContext.tagScope & NOSCRIPT_SCOPE;
3770 const asyncProp = props.async;
3771 if (
3772 typeof props.src !== 'string' ||
3773 !props.src ||
3774 !(
3775 asyncProp &&
3776 typeof asyncProp !== 'function' &&
3777 typeof asyncProp !== 'symbol'
3778 ) ||
3779 props.onLoad ||
3780 props.onError ||
3781 formatContext.insertionMode === SVG_MODE ||
3782 noscriptTagInScope ||
3783 props.itemProp != null
3784 ) {
3785 // This script will not be a resource, we bailout early and emit it in place.
3786 return pushScriptImpl(target, props);
3787 }
3788
3789 const src = props.src;
3790 const key = getResourceKey(src);
3791 // We can make this <script> into a ScriptResource
3792
3793 let resources, preloads;
3794 if (props.type === 'module') {
3795 resources = resumableState.moduleScriptResources;
3796 preloads = renderState.preloads.moduleScripts;
3797 } else {
3798 resources = resumableState.scriptResources;
3799 preloads = renderState.preloads.scripts;
3800 }
3801
3802 const hasKey = resources.hasOwnProperty(key);
3803 const resourceState = hasKey ? resources[key] : undefined;
3804 if (resourceState !== EXISTS) {
3805 // We are going to create this resource now so it is marked as Exists
3806 resources[key] = EXISTS;
3807
3808 let scriptProps = props;
3809 if (resourceState) {
3810 // When resourceState is truty it is a Preload state. We cast it for clarity
3811 const preloadState: Preloaded | PreloadedWithCredentials = resourceState;
3812 if (preloadState.length === 2) {
3813 scriptProps = {...props};
3814 adoptPreloadCredentials(scriptProps, preloadState);
3815 }
3816
3817 const preloadResource = preloads.get(key);
3818 if (preloadResource) {

Callers 1

pushStartInstanceFunction · 0.85

Calls 6

pushScriptImplFunction · 0.85
adoptPreloadCredentialsFunction · 0.85
addMethod · 0.80
getResourceKeyFunction · 0.70
getMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected