( href: string, options?: ?PreloadModuleImplOptions, )
| 6509 | } |
| 6510 | |
| 6511 | function preloadModule( |
| 6512 | href: string, |
| 6513 | options?: ?PreloadModuleImplOptions, |
| 6514 | ): void { |
| 6515 | const request = resolveRequest(); |
| 6516 | if (!request) { |
| 6517 | // In async contexts we can sometimes resolve resources from AsyncLocalStorage. If we can't we can also |
| 6518 | // possibly get them from the stack if we are not in an async context. Since we were not able to resolve |
| 6519 | // the resources for this call in either case we opt to do nothing. We can consider making this a warning |
| 6520 | // but there may be times where calling a function outside of render is intentional (i.e. to warm up data |
| 6521 | // fetching) and we don't want to warn in those cases. |
| 6522 | previousDispatcher.m(/* preloadModule */ href, options); |
| 6523 | return; |
| 6524 | } |
| 6525 | const resumableState = getResumableState(request); |
| 6526 | const renderState = getRenderState(request); |
| 6527 | if (href) { |
| 6528 | const key = getResourceKey(href); |
| 6529 | const as = |
| 6530 | options && typeof options.as === 'string' ? options.as : 'script'; |
| 6531 | |
| 6532 | let resource; |
| 6533 | switch (as) { |
| 6534 | case 'script': { |
| 6535 | if (resumableState.moduleScriptResources.hasOwnProperty(key)) { |
| 6536 | // we can return if we already have this resource |
| 6537 | return; |
| 6538 | } |
| 6539 | resource = ([]: Resource); |
| 6540 | resumableState.moduleScriptResources[key] = |
| 6541 | options && |
| 6542 | (typeof options.crossOrigin === 'string' || |
| 6543 | typeof options.integrity === 'string') |
| 6544 | ? [options.crossOrigin, options.integrity] |
| 6545 | : PRELOAD_NO_CREDS; |
| 6546 | renderState.preloads.moduleScripts.set(key, resource); |
| 6547 | break; |
| 6548 | } |
| 6549 | default: { |
| 6550 | const hasAsType = |
| 6551 | resumableState.moduleUnknownResources.hasOwnProperty(as); |
| 6552 | let resources; |
| 6553 | if (hasAsType) { |
| 6554 | resources = resumableState.unknownResources[as]; |
| 6555 | if (resources.hasOwnProperty(key)) { |
| 6556 | // we can return if we already have this resource |
| 6557 | return; |
| 6558 | } |
| 6559 | } else { |
| 6560 | resources = ({}: ResumableState['moduleUnknownResources']['asType']); |
| 6561 | resumableState.moduleUnknownResources[as] = resources; |
| 6562 | } |
| 6563 | resource = ([]: Resource); |
| 6564 | resources[key] = PRELOAD_NO_CREDS; |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | pushLinkImpl( |
nothing calls this directly
no test coverage detected