Skip to content

Commit 0b9dbb3

Browse files
committed
chore: add comments
1 parent b29c636 commit 0b9dbb3

File tree

1 file changed

+4
-1
lines changed
  • packages/runtime/src/helpers

1 file changed

+4
-1
lines changed

packages/runtime/src/helpers/edge.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,19 @@ export const writeEdgeFunctions = async ({
461461
...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName)),
462462
)
463463
}
464+
// Functions (i.e. not middleware, but edge SSR and API routes)
464465
if (typeof middlewareManifest.functions === 'object') {
465466
// When using the app dir, we also need to check if the EF matches a page
466467
const appPathRoutesManifest = await loadAppPathRoutesManifest(netlifyConfig)
467468

469+
// A map of all route pages to their page regex. This is used for pages dir and appDir.
468470
const pageRegexMap = new Map(
469471
[...(routesManifest.dynamicRoutes || []), ...(routesManifest.staticRoutes || [])].map((route) => [
470472
route.page,
471473
route.regex,
472474
]),
473475
)
474-
476+
// Create a map of pages-dir routes to their data route regex (appDir uses the same route as the HTML)
475477
const dataRoutesMap = new Map(
476478
[...(routesManifest.dataRoutes || [])].map((route) => [route.page, route.dataRouteRegex]),
477479
)
@@ -497,6 +499,7 @@ export const writeEdgeFunctions = async ({
497499
// cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir
498500
cache: usesAppDir ? 'manual' : undefined,
499501
})
502+
// pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too
500503
const dataRoute = dataRoutesMap.get(edgeFunctionDefinition.page)
501504
if (dataRoute) {
502505
manifest.functions.push({

0 commit comments

Comments
 (0)