( base: string, resolvedManifest: ResolvedManifest | undefined, options: PreloaderOptions | boolean | undefined, referencedBundles: string[], nonce?: string )
| 90 | }; |
| 91 | |
| 92 | export const includePreloader = ( |
| 93 | base: string, |
| 94 | resolvedManifest: ResolvedManifest | undefined, |
| 95 | options: PreloaderOptions | boolean | undefined, |
| 96 | referencedBundles: string[], |
| 97 | nonce?: string |
| 98 | ): JSXNode | null => { |
| 99 | if (referencedBundles.length === 0 || options === false) { |
| 100 | return null; |
| 101 | } |
| 102 | const { ssrPreloads, ssrPreloadProbability } = normalizePreLoaderOptions( |
| 103 | typeof options === 'boolean' ? undefined : options |
| 104 | ); |
| 105 | let allowed = ssrPreloads; |
| 106 | |
| 107 | const nodes: JSXNode[] = []; |
| 108 | |
| 109 | if (import.meta.env.DEV) { |
| 110 | // Vite dev server active |
| 111 | // in dev, all bundles are absolute paths from the base url, not /build |
| 112 | base = import.meta.env.BASE_URL; |
| 113 | if (base.endsWith('/')) { |
| 114 | base = base.slice(0, -1); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | const links = []; |
| 119 | |
| 120 | const manifestHash = resolvedManifest?.manifest.manifestHash; |
| 121 | if (allowed) { |
| 122 | const preloaderBundle = resolvedManifest?.manifest.preloader; |
| 123 | const coreBundle = resolvedManifest?.manifest.core; |
| 124 | const expandedBundles = expandBundles(referencedBundles, resolvedManifest); |
| 125 | // Keep the same as in getQueue (but *10) |
| 126 | let probability = 4; |
| 127 | const tenXMinProbability = ssrPreloadProbability * 10; |
| 128 | for (const hrefOrProbability of expandedBundles) { |
| 129 | if (typeof hrefOrProbability === 'string') { |
| 130 | if (probability < tenXMinProbability) { |
| 131 | break; |
| 132 | } |
| 133 | // we already preload the preloader and core bundles |
| 134 | if (hrefOrProbability === preloaderBundle || hrefOrProbability === coreBundle) { |
| 135 | continue; |
| 136 | } |
| 137 | links.push(hrefOrProbability); |
| 138 | if (--allowed === 0) { |
| 139 | break; |
| 140 | } |
| 141 | } else { |
| 142 | probability = hrefOrProbability; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | const preloaderPath = simplifyPath(base, manifestHash && resolvedManifest?.manifest.preloader); |
| 148 | const insertLinks = links.length |
| 149 | ? /** |
no test coverage detected
searching dependent graphs…