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

Function prefetch

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

Source from the content-addressed store, hash-verified

380}
381
382export async function prefetch(path, options = {}) {
383 // Clean the path
384 path = getRoutePath(path)
385
386 const { type } = options
387
388 // If it's priority, we stop the queue temporarily
389 if (options.priority) {
390 requestPool.stop()
391 }
392
393 let data
394 if (type === 'data') {
395 data = await prefetchData(path, options)
396 } else if (type === 'template') {
397 await prefetchTemplate(path, options)
398 } else {
399 ;[data] = await Promise.all([
400 prefetchData(path, options),
401 prefetchTemplate(path, options),
402 ])
403 }
404
405 // If it was priority, start the queue again
406 if (options.priority) {
407 requestPool.start()
408 }
409
410 return data
411}
412
413export function isPrefetchableRoute(path) {
414 // when rendering static pages we dont need this at all

Callers 6

registerTemplatesFunction · 0.85
runFunction · 0.85
reloadClientDataFunction · 0.85
Routes.jsFile · 0.85
useRouteDataFunction · 0.85
usePrefetchFunction · 0.85

Calls 3

getRoutePathFunction · 0.90
prefetchDataFunction · 0.85
prefetchTemplateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…