MCPcopy
hub / github.com/vercel/next.js / loadRoute

Function loadRoute

packages/next/src/client/route-loader.ts:332–377  ·  view source on GitHub ↗
(route: string, prefetch?: boolean)

Source from the content-addressed store, hash-verified

330 })
331 },
332 loadRoute(route: string, prefetch?: boolean) {
333 return withFuture<RouteLoaderEntry>(route, routes, () => {
334 let devBuildPromiseResolve: () => void
335
336 if (process.env.NODE_ENV === 'development') {
337 devBuildPromise = new Promise<void>((resolve) => {
338 devBuildPromiseResolve = resolve
339 })
340 }
341
342 return resolvePromiseWithTimeout(
343 getFilesForRoute(assetPrefix, route)
344 .then(({ scripts, css }) => {
345 return Promise.all([
346 entrypoints.has(route)
347 ? []
348 : Promise.all(scripts.map(maybeExecuteScript)),
349 Promise.all(css.map(fetchStyleSheet)),
350 ] as const)
351 })
352 .then((res) => {
353 return this.whenEntrypoint(route).then((entrypoint) => ({
354 entrypoint,
355 styles: res[1],
356 }))
357 }),
358 markAssetError(new Error(`Route did not complete loading: ${route}`)),
359 devBuildPromise
360 )
361 .then(({ entrypoint, styles }) => {
362 const res: RouteLoaderEntry = Object.assign<
363 { styles: RouteStyleSheet[] },
364 RouteEntrypoint
365 >({ styles: styles! }, entrypoint)
366 return 'error' in entrypoint ? entrypoint : res
367 })
368 .catch((err) => {
369 if (prefetch) {
370 // we don't want to cache errors during prefetch
371 throw err
372 }
373 return { error: err }
374 })
375 .finally(() => devBuildPromiseResolve?.())
376 })
377 },
378 prefetch(route: string): Promise<void> {
379 // https://github.com/GoogleChromeLabs/quicklink/blob/453a661fa1fa940e2d2e044452398e38c67a98fb/src/index.mjs#L115-L118
380 // License: Apache 2.0

Callers

nothing calls this directly

Calls 12

withFutureFunction · 0.85
getFilesForRouteFunction · 0.85
markAssetErrorFunction · 0.85
finallyMethod · 0.80
thenMethod · 0.80
allMethod · 0.80
whenEntrypointMethod · 0.80
assignMethod · 0.80
catchMethod · 0.45
hasMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected