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

Function getFilesForRoute

packages/next/src/client/route-loader.ts:208–240  ·  view source on GitHub ↗
(
  assetPrefix: string,
  route: string
)

Source from the content-addressed store, hash-verified

206 css: string[]
207}
208function getFilesForRoute(
209 assetPrefix: string,
210 route: string
211): Promise<RouteFiles> {
212 if (process.env.NODE_ENV === 'development') {
213 const scriptUrl =
214 assetPrefix +
215 '/_next/static/chunks/pages' +
216 encodeURIPath(getAssetPathFromRoute(route, '.js')) +
217 getAssetTokenQuery()
218 return Promise.resolve({
219 scripts: [__unsafeCreateTrustedScriptURL(scriptUrl)],
220 // Styles are handled by `style-loader` in development:
221 css: [],
222 })
223 }
224 return getClientBuildManifest().then((manifest) => {
225 if (!(route in manifest)) {
226 throw markAssetError(new Error(`Failed to lookup route: ${route}`))
227 }
228 const allFiles = manifest[route].map(
229 (entry) => assetPrefix + '/_next/' + encodeURIPath(entry)
230 )
231 return {
232 scripts: allFiles
233 .filter((v) => v.endsWith('.js'))
234 .map((v) => __unsafeCreateTrustedScriptURL(v) + getAssetTokenQuery()),
235 css: allFiles
236 .filter((v) => v.endsWith('.css'))
237 .map((v) => v + getAssetTokenQuery()),
238 }
239 })
240}
241
242export function createRouteLoader(assetPrefix: string): RouteLoader {
243 const entrypoints: Map<string, Future<RouteEntrypoint> | RouteEntrypoint> =

Callers 2

loadRouteFunction · 0.85
prefetchFunction · 0.85

Calls 11

encodeURIPathFunction · 0.90
getAssetTokenQueryFunction · 0.90
getAssetPathFromRouteFunction · 0.85
markAssetErrorFunction · 0.85
thenMethod · 0.80
getClientBuildManifestFunction · 0.70
resolveMethod · 0.65
mapMethod · 0.45
filterMethod · 0.45
endsWithMethod · 0.45

Tested by

no test coverage detected