(src: string, options?: ?PreinitScriptOptions)
| 4906 | } |
| 4907 | |
| 4908 | function 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 | |
| 4961 | function preinitModuleScript( |
| 4962 | src: string, |
nothing calls this directly
no test coverage detected