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

Function preinitScript

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js:4908–4959  ·  view source on GitHub ↗
(src: string, options?: ?PreinitScriptOptions)

Source from the content-addressed store, hash-verified

4906}
4907
4908function preinitScript(src: string, options?: ?PreinitScriptOptions) {
4909 previousDispatcher.X(/* preinitScript */ src, options);
4910
4911 const ownerDocument = getGlobalDocument();
4912 if (ownerDocument && src) {
4913 const scripts = getResourcesFromRoot(ownerDocument).hoistableScripts;
4914
4915 const key = getScriptKey(src);
4916
4917 // Check if this resource already exists
4918 let resource = scripts.get(key);
4919 if (resource) {
4920 // We can early return. The resource exists and there is nothing
4921 // more to do
4922 return;
4923 }
4924
4925 // Attempt to hydrate instance from DOM
4926 let instance: null | Instance = ownerDocument.querySelector(
4927 getScriptSelectorFromKey(key),
4928 );
4929 if (!instance) {
4930 // Construct a new instance and insert it
4931 const scriptProps = Object.assign(
4932 ({
4933 src,
4934 async: true,
4935 }: ScriptProps),
4936 options,
4937 );
4938 // Adopt certain preload props
4939 const preloadProps = preloadPropsMap.get(key);
4940 if (preloadProps) {
4941 adoptPreloadPropsForScript(scriptProps, preloadProps);
4942 }
4943 instance = ownerDocument.createElement('script');
4944 markNodeAsHoistable(instance);
4945 setInitialProperties(instance, 'link', scriptProps);
4946 (ownerDocument.head: any).appendChild(instance);
4947 }
4948
4949 // Construct a Resource and cache it
4950 resource = {
4951 type: 'script',
4952 instance,
4953 count: 1,
4954 state: null,
4955 };
4956 scripts.set(key, resource);
4957 return;
4958 }
4959}
4960
4961function preinitModuleScript(
4962 src: string,

Callers

nothing calls this directly

Calls 10

getResourcesFromRootFunction · 0.90
markNodeAsHoistableFunction · 0.90
setInitialPropertiesFunction · 0.90
getGlobalDocumentFunction · 0.85
getScriptKeyFunction · 0.85
getScriptSelectorFromKeyFunction · 0.85
setMethod · 0.80
getMethod · 0.65
assignMethod · 0.45

Tested by

no test coverage detected