MCPcopy Create free account
hub / github.com/stenciljs/core / addModulePreloads

Function addModulePreloads

src/compiler/prerender/prerender-optimize.ts:173–193  ·  view source on GitHub ↗
(
  doc: Document,
  hydrateOpts: d.PrerenderHydrateOptions,
  hydrateResults: d.HydrateResults,
  componentGraph: Map<string, string[]>,
)

Source from the content-addressed store, hash-verified

171 .trim();
172
173export const addModulePreloads = (
174 doc: Document,
175 hydrateOpts: d.PrerenderHydrateOptions,
176 hydrateResults: d.HydrateResults,
177 componentGraph: Map<string, string[]>,
178) => {
179 if (!componentGraph) {
180 return false;
181 }
182
183 const staticComponents = hydrateOpts.staticComponents || [];
184
185 const cmpTags = hydrateResults.components.filter((cmp) => !staticComponents.includes(cmp.tag));
186
187 const modulePreloads = unique(
188 flatOne(cmpTags.map((cmp) => getScopeId(cmp.tag, cmp.mode)).map((scopeId) => componentGraph.get(scopeId) || [])),
189 );
190
191 injectModulePreloads(doc, modulePreloads);
192 return true;
193};
194
195export const removeModulePreloads = (doc: Document) => {
196 const links = doc.querySelectorAll('link[rel="modulepreload"]');

Callers 1

prerenderWorkerFunction · 0.90

Calls 5

getScopeIdFunction · 0.90
injectModulePreloadsFunction · 0.90
uniqueFunction · 0.85
flatOneFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected