MCPcopy Create free account
hub / github.com/react-static/react-static / prefetchTemplate

Function prefetchTemplate

packages/react-static/src/browser/index.js:346–380  ·  view source on GitHub ↗
(path, { priority } = {})

Source from the content-addressed store, hash-verified

344}
345
346export async function prefetchTemplate(path, { priority } = {}) {
347 // Clean the path
348 path = getRoutePath(path)
349 // Get route info so we can check if path has any data
350 const routeInfo = await getRouteInfo(path, { priority })
351
352 if (routeInfo) {
353 // Make sure to use the path as defined in the routeInfo object here.
354 // This will make sure 404 route info returned from getRouteInfo is handled correctly.
355 registerTemplateForPath(routeInfo.path, routeInfo.template)
356 }
357
358 // Preload the template if available
359 const Template = templatesByPath[path]
360 if (!Template) {
361 // If no template was found, mark it with an error
362 templateErrorByPath[path] = true
363 return
364 }
365
366 // If we didn't no route info was return, there is nothing more to do here
367 if (!routeInfo) {
368 return Template
369 }
370
371 if (!routeInfo.templateLoaded && Template.preload) {
372 if (priority) {
373 await Template.preload()
374 } else {
375 await requestPool.add(() => Template.preload())
376 }
377 routeInfo.templateLoaded = true
378 }
379 return Template
380}
381
382export async function prefetch(path, options = {}) {
383 // Clean the path

Callers 1

prefetchFunction · 0.85

Calls 3

getRoutePathFunction · 0.90
getRouteInfoFunction · 0.85
registerTemplateForPathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…