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

Function preloadModule

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js:4773–4828  ·  view source on GitHub ↗
(href: string, options?: ?PreloadModuleImplOptions)

Source from the content-addressed store, hash-verified

4771}
4772
4773function preloadModule(href: string, options?: ?PreloadModuleImplOptions) {
4774 previousDispatcher.m(/* preloadModule */ href, options);
4775 const ownerDocument = getGlobalDocument();
4776 if (ownerDocument && href) {
4777 const as =
4778 options && typeof options.as === 'string' ? options.as : 'script';
4779 const preloadSelector = `link[rel="modulepreload"][as="${escapeSelectorAttributeValueInsideDoubleQuotes(
4780 as,
4781 )}"][href="${escapeSelectorAttributeValueInsideDoubleQuotes(href)}"]`;
4782 // Some preloads are keyed under their selector. This happens when the preload is for
4783 // an arbitrary type. Other preloads are keyed under the resource key they represent a preload for.
4784 // Here we figure out which key to use to determine if we have a preload already.
4785 let key = preloadSelector;
4786 switch (as) {
4787 case 'audioworklet':
4788 case 'paintworklet':
4789 case 'serviceworker':
4790 case 'sharedworker':
4791 case 'worker':
4792 case 'script': {
4793 key = getScriptKey(href);
4794 break;
4795 }
4796 }
4797
4798 if (!preloadPropsMap.has(key)) {
4799 const props: PreloadModuleProps = Object.assign(
4800 ({
4801 rel: 'modulepreload',
4802 href,
4803 }: PreloadModuleProps),
4804 options,
4805 );
4806 preloadPropsMap.set(key, props);
4807
4808 if (null === ownerDocument.querySelector(preloadSelector)) {
4809 switch (as) {
4810 case 'audioworklet':
4811 case 'paintworklet':
4812 case 'serviceworker':
4813 case 'sharedworker':
4814 case 'worker':
4815 case 'script': {
4816 if (ownerDocument.querySelector(getScriptSelectorFromKey(key))) {
4817 return;
4818 }
4819 }
4820 }
4821 const instance = ownerDocument.createElement('link');
4822 setInitialProperties(instance, 'link', props);
4823 markNodeAsHoistable(instance);
4824 (ownerDocument.head: any).appendChild(instance);
4825 }
4826 }
4827 }
4828}
4829
4830function preinitStyle(

Callers

nothing calls this directly

Calls 10

setInitialPropertiesFunction · 0.90
markNodeAsHoistableFunction · 0.90
getGlobalDocumentFunction · 0.85
getScriptKeyFunction · 0.85
getScriptSelectorFromKeyFunction · 0.85
setMethod · 0.80
hasMethod · 0.65
mMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected