vinext 0.0.39 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/build/standalone.js +7 -0
  2. package/dist/build/standalone.js.map +1 -1
  3. package/dist/entries/app-rsc-entry.d.ts +2 -1
  4. package/dist/entries/app-rsc-entry.js +131 -245
  5. package/dist/entries/app-rsc-entry.js.map +1 -1
  6. package/dist/index.d.ts +32 -1
  7. package/dist/index.js +80 -6
  8. package/dist/index.js.map +1 -1
  9. package/dist/plugins/server-externals-manifest.d.ts +11 -1
  10. package/dist/plugins/server-externals-manifest.js +10 -3
  11. package/dist/plugins/server-externals-manifest.js.map +1 -1
  12. package/dist/routing/app-router.d.ts +10 -2
  13. package/dist/routing/app-router.js +37 -22
  14. package/dist/routing/app-router.js.map +1 -1
  15. package/dist/server/app-page-response.d.ts +12 -1
  16. package/dist/server/app-page-response.js +26 -7
  17. package/dist/server/app-page-response.js.map +1 -1
  18. package/dist/server/app-page-route-wiring.d.ts +79 -0
  19. package/dist/server/app-page-route-wiring.js +165 -0
  20. package/dist/server/app-page-route-wiring.js.map +1 -0
  21. package/dist/server/app-page-stream.js +3 -0
  22. package/dist/server/app-page-stream.js.map +1 -1
  23. package/dist/server/app-route-handler-response.js +4 -1
  24. package/dist/server/app-route-handler-response.js.map +1 -1
  25. package/dist/server/app-router-entry.d.ts +6 -1
  26. package/dist/server/app-router-entry.js +9 -2
  27. package/dist/server/app-router-entry.js.map +1 -1
  28. package/dist/server/prod-server.d.ts +1 -1
  29. package/dist/server/prod-server.js +37 -11
  30. package/dist/server/prod-server.js.map +1 -1
  31. package/dist/server/worker-utils.d.ts +4 -1
  32. package/dist/server/worker-utils.js +31 -1
  33. package/dist/server/worker-utils.js.map +1 -1
  34. package/dist/shims/error-boundary.d.ts +13 -4
  35. package/dist/shims/error-boundary.js +23 -3
  36. package/dist/shims/error-boundary.js.map +1 -1
  37. package/dist/shims/head.js.map +1 -1
  38. package/dist/shims/navigation.d.ts +16 -1
  39. package/dist/shims/navigation.js +18 -3
  40. package/dist/shims/navigation.js.map +1 -1
  41. package/dist/shims/router.js +127 -38
  42. package/dist/shims/router.js.map +1 -1
  43. package/dist/shims/script.js.map +1 -1
  44. package/dist/shims/server.d.ts +17 -4
  45. package/dist/shims/server.js +91 -73
  46. package/dist/shims/server.js.map +1 -1
  47. package/dist/shims/slot.d.ts +28 -0
  48. package/dist/shims/slot.js +49 -0
  49. package/dist/shims/slot.js.map +1 -0
  50. package/package.json +1 -2
@@ -1,6 +1,16 @@
1
1
  import { Plugin } from "vite";
2
2
 
3
3
  //#region src/plugins/server-externals-manifest.d.ts
4
+ /**
5
+ * Extract the npm package name from a bare module specifier.
6
+ *
7
+ * Returns null for:
8
+ * - Relative imports ("./foo", "../bar")
9
+ * - Absolute paths ("/abs/path")
10
+ * - Node built-ins ("node:fs")
11
+ * - Package self-references ("#imports")
12
+ */
13
+ declare function packageNameFromSpecifier(specifier: string): string | null;
4
14
  /**
5
15
  * vinext:server-externals-manifest
6
16
  *
@@ -23,5 +33,5 @@ import { Plugin } from "vite";
23
33
  */
24
34
  declare function createServerExternalsManifestPlugin(): Plugin;
25
35
  //#endregion
26
- export { createServerExternalsManifestPlugin };
36
+ export { createServerExternalsManifestPlugin, packageNameFromSpecifier };
27
37
  //# sourceMappingURL=server-externals-manifest.d.ts.map
@@ -1,6 +1,8 @@
1
+ import { builtinModules } from "node:module";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  //#region src/plugins/server-externals-manifest.ts
5
+ const BUILTIN_MODULES = new Set(builtinModules.flatMap((name) => name.startsWith("node:") ? [name, name.slice(5)] : [name, `node:${name}`]));
4
6
  /**
5
7
  * Extract the npm package name from a bare module specifier.
6
8
  *
@@ -11,13 +13,16 @@ import path from "node:path";
11
13
  * - Package self-references ("#imports")
12
14
  */
13
15
  function packageNameFromSpecifier(specifier) {
14
- if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("node:") || specifier.startsWith("#")) return null;
16
+ if (!specifier || specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("\\") || specifier.startsWith("#")) return null;
17
+ if (/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(specifier)) return null;
15
18
  if (specifier.startsWith("@")) {
16
19
  const parts = specifier.split("/");
17
20
  if (parts.length >= 2) return `${parts[0]}/${parts[1]}`;
18
21
  return null;
19
22
  }
20
- return specifier.split("/")[0] || null;
23
+ const packageName = specifier.split("/")[0] || null;
24
+ if (!packageName || BUILTIN_MODULES.has(specifier) || BUILTIN_MODULES.has(packageName)) return null;
25
+ return packageName;
21
26
  }
22
27
  /**
23
28
  * vinext:server-externals-manifest
@@ -55,9 +60,11 @@ function createServerExternalsManifestPlugin() {
55
60
  const dir = options.dir;
56
61
  if (!dir) return;
57
62
  if (!outDir) outDir = path.basename(dir) === "server" ? dir : path.dirname(dir);
63
+ const bundleFiles = new Set(Object.keys(bundle));
58
64
  for (const item of Object.values(bundle)) {
59
65
  if (item.type !== "chunk") continue;
60
66
  for (const specifier of [...item.imports, ...item.dynamicImports]) {
67
+ if (bundleFiles.has(specifier)) continue;
61
68
  const pkg = packageNameFromSpecifier(specifier);
62
69
  if (pkg) externals.add(pkg);
63
70
  }
@@ -71,6 +78,6 @@ function createServerExternalsManifestPlugin() {
71
78
  };
72
79
  }
73
80
  //#endregion
74
- export { createServerExternalsManifestPlugin };
81
+ export { createServerExternalsManifestPlugin, packageNameFromSpecifier };
75
82
 
76
83
  //# sourceMappingURL=server-externals-manifest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-externals-manifest.js","names":[],"sources":["../../src/plugins/server-externals-manifest.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { Plugin } from \"vite\";\n\n/**\n * Extract the npm package name from a bare module specifier.\n *\n * Returns null for:\n * - Relative imports (\"./foo\", \"../bar\")\n * - Absolute paths (\"/abs/path\")\n * - Node built-ins (\"node:fs\")\n * - Package self-references (\"#imports\")\n */\nfunction packageNameFromSpecifier(specifier: string): string | null {\n if (\n specifier.startsWith(\".\") ||\n specifier.startsWith(\"/\") ||\n specifier.startsWith(\"node:\") ||\n specifier.startsWith(\"#\")\n ) {\n return null;\n }\n\n if (specifier.startsWith(\"@\")) {\n const parts = specifier.split(\"/\");\n if (parts.length >= 2) {\n return `${parts[0]}/${parts[1]}`;\n }\n return null;\n }\n\n return specifier.split(\"/\")[0] || null;\n}\n\n/**\n * vinext:server-externals-manifest\n *\n * A `writeBundle` plugin that collects the packages left external by the\n * SSR/RSC bundler and writes them to `<outDir>/vinext-externals.json`.\n *\n * With `noExternal: true`, Vite bundles almost everything — only packages\n * explicitly listed in `ssr.external` / `resolve.external` remain as live\n * imports in the server bundle. Those packages are exactly what a standalone\n * deployment needs in `node_modules/`.\n *\n * Using the bundler's own import graph (`chunk.imports` + `chunk.dynamicImports`)\n * is authoritative: no text parsing, no regex, no guessing.\n *\n * The written JSON is an array of package-name strings, e.g.:\n * [\"react\", \"react-dom\", \"react-dom/server\"]\n *\n * `emitStandaloneOutput` reads this file and uses it as the seed list for the\n * BFS `node_modules/` copy, replacing the old regex-scan approach.\n */\nexport function createServerExternalsManifestPlugin(): Plugin {\n // Accumulate external specifiers across all server environments (rsc + ssr).\n // Both environments run writeBundle; we merge their results so Pages Router\n // builds (ssr only) and App Router builds (rsc + ssr) both produce a\n // complete manifest.\n const externals = new Set<string>();\n let outDir: string | null = null;\n\n return {\n name: \"vinext:server-externals-manifest\",\n apply: \"build\",\n enforce: \"post\",\n\n writeBundle: {\n sequential: true,\n order: \"post\",\n handler(options, bundle) {\n const envName = this.environment?.name;\n // Only collect from server environments (rsc = App Router RSC build,\n // ssr = Pages Router SSR build or App Router SSR build).\n if (envName !== \"rsc\" && envName !== \"ssr\") return;\n\n const dir = options.dir;\n if (!dir) return;\n\n // Use the first server env's outDir parent as the canonical server dir.\n // For Pages Router: options.dir IS dist/server.\n // For App Router RSC: options.dir is dist/server.\n // For App Router SSR: options.dir is dist/server/ssr.\n // We always want dist/server as the manifest location.\n if (!outDir) {\n // The server bundle outputs to dist/server for all environments except\n // App Router SSR, which outputs to dist/server/ssr. We always want\n // dist/server as the manifest location. Rather than hard-coding \"ssr\",\n // treat any sub-directory of dist/server (basename !== \"server\") as a\n // sub-env and walk up one level. This handles any future sub-directory\n // environments (e.g. \"edge\") without code changes.\n // Note: using basename rather than a walk-up avoids misfiring when a\n // user's project path contains a \"server\" segment above the dist output\n // (e.g. /home/user/server/my-app/).\n outDir = path.basename(dir) === \"server\" ? dir : path.dirname(dir);\n }\n\n for (const item of Object.values(bundle)) {\n if (item.type !== \"chunk\") continue;\n // In Rollup output, item.imports normally contains filenames of other\n // chunks in the bundle. But externalized packages remain as bare npm\n // specifiers (e.g. \"react\", \"@mdx-js/react\") since they were never\n // bundled into chunk files. packageNameFromSpecifier filters out chunk\n // filenames (relative/absolute paths) and extracts the package name from\n // bare specifiers — which is exactly what the standalone BFS needs.\n for (const specifier of [...item.imports, ...item.dynamicImports]) {\n const pkg = packageNameFromSpecifier(specifier);\n if (pkg) externals.add(pkg);\n }\n }\n\n // After the last expected writeBundle call, flush to disk.\n // We flush on every call since we don't know ahead of time how many\n // environments will fire — overwriting with the accumulated set is safe.\n if (outDir && fs.existsSync(outDir)) {\n const manifestPath = path.join(outDir, \"vinext-externals.json\");\n fs.writeFileSync(manifestPath, JSON.stringify([...externals], null, 2) + \"\\n\", \"utf-8\");\n }\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAS,yBAAyB,WAAkC;AAClE,KACE,UAAU,WAAW,IAAI,IACzB,UAAU,WAAW,IAAI,IACzB,UAAU,WAAW,QAAQ,IAC7B,UAAU,WAAW,IAAI,CAEzB,QAAO;AAGT,KAAI,UAAU,WAAW,IAAI,EAAE;EAC7B,MAAM,QAAQ,UAAU,MAAM,IAAI;AAClC,MAAI,MAAM,UAAU,EAClB,QAAO,GAAG,MAAM,GAAG,GAAG,MAAM;AAE9B,SAAO;;AAGT,QAAO,UAAU,MAAM,IAAI,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;AAuBpC,SAAgB,sCAA8C;CAK5D,MAAM,4BAAY,IAAI,KAAa;CACnC,IAAI,SAAwB;AAE5B,QAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EAET,aAAa;GACX,YAAY;GACZ,OAAO;GACP,QAAQ,SAAS,QAAQ;IACvB,MAAM,UAAU,KAAK,aAAa;AAGlC,QAAI,YAAY,SAAS,YAAY,MAAO;IAE5C,MAAM,MAAM,QAAQ;AACpB,QAAI,CAAC,IAAK;AAOV,QAAI,CAAC,OAUH,UAAS,KAAK,SAAS,IAAI,KAAK,WAAW,MAAM,KAAK,QAAQ,IAAI;AAGpE,SAAK,MAAM,QAAQ,OAAO,OAAO,OAAO,EAAE;AACxC,SAAI,KAAK,SAAS,QAAS;AAO3B,UAAK,MAAM,aAAa,CAAC,GAAG,KAAK,SAAS,GAAG,KAAK,eAAe,EAAE;MACjE,MAAM,MAAM,yBAAyB,UAAU;AAC/C,UAAI,IAAK,WAAU,IAAI,IAAI;;;AAO/B,QAAI,UAAU,GAAG,WAAW,OAAO,EAAE;KACnC,MAAM,eAAe,KAAK,KAAK,QAAQ,wBAAwB;AAC/D,QAAG,cAAc,cAAc,KAAK,UAAU,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,QAAQ;;;GAG5F;EACF"}
1
+ {"version":3,"file":"server-externals-manifest.js","names":[],"sources":["../../src/plugins/server-externals-manifest.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { builtinModules } from \"node:module\";\nimport type { Plugin } from \"vite\";\n\nconst BUILTIN_MODULES = new Set(\n builtinModules.flatMap((name) =>\n name.startsWith(\"node:\") ? [name, name.slice(5)] : [name, `node:${name}`],\n ),\n);\n\n/**\n * Extract the npm package name from a bare module specifier.\n *\n * Returns null for:\n * - Relative imports (\"./foo\", \"../bar\")\n * - Absolute paths (\"/abs/path\")\n * - Node built-ins (\"node:fs\")\n * - Package self-references (\"#imports\")\n */\nexport function packageNameFromSpecifier(specifier: string): string | null {\n if (\n !specifier ||\n specifier.startsWith(\".\") ||\n specifier.startsWith(\"/\") ||\n specifier.startsWith(\"\\\\\") ||\n specifier.startsWith(\"#\")\n ) {\n return null;\n }\n\n // External specifiers can include non-package schemes such as\n // \"virtual:vite-rsc\" or \"file:...\". Those are never npm packages.\n if (/^[a-zA-Z][a-zA-Z\\d+.-]*:/.test(specifier)) {\n return null;\n }\n\n if (specifier.startsWith(\"@\")) {\n const parts = specifier.split(\"/\");\n if (parts.length >= 2) {\n return `${parts[0]}/${parts[1]}`;\n }\n return null;\n }\n\n const packageName = specifier.split(\"/\")[0] || null;\n if (!packageName || BUILTIN_MODULES.has(specifier) || BUILTIN_MODULES.has(packageName)) {\n return null;\n }\n return packageName;\n}\n\n/**\n * vinext:server-externals-manifest\n *\n * A `writeBundle` plugin that collects the packages left external by the\n * SSR/RSC bundler and writes them to `<outDir>/vinext-externals.json`.\n *\n * With `noExternal: true`, Vite bundles almost everything — only packages\n * explicitly listed in `ssr.external` / `resolve.external` remain as live\n * imports in the server bundle. Those packages are exactly what a standalone\n * deployment needs in `node_modules/`.\n *\n * Using the bundler's own import graph (`chunk.imports` + `chunk.dynamicImports`)\n * is authoritative: no text parsing, no regex, no guessing.\n *\n * The written JSON is an array of package-name strings, e.g.:\n * [\"react\", \"react-dom\", \"react-dom/server\"]\n *\n * `emitStandaloneOutput` reads this file and uses it as the seed list for the\n * BFS `node_modules/` copy, replacing the old regex-scan approach.\n */\nexport function createServerExternalsManifestPlugin(): Plugin {\n // Accumulate external specifiers across all server environments (rsc + ssr).\n // Both environments run writeBundle; we merge their results so Pages Router\n // builds (ssr only) and App Router builds (rsc + ssr) both produce a\n // complete manifest.\n const externals = new Set<string>();\n let outDir: string | null = null;\n\n return {\n name: \"vinext:server-externals-manifest\",\n apply: \"build\",\n enforce: \"post\",\n\n writeBundle: {\n sequential: true,\n order: \"post\",\n handler(options, bundle) {\n const envName = this.environment?.name;\n // Only collect from server environments (rsc = App Router RSC build,\n // ssr = Pages Router SSR build or App Router SSR build).\n if (envName !== \"rsc\" && envName !== \"ssr\") return;\n\n const dir = options.dir;\n if (!dir) return;\n\n // Use the first server env's outDir parent as the canonical server dir.\n // For Pages Router: options.dir IS dist/server.\n // For App Router RSC: options.dir is dist/server.\n // For App Router SSR: options.dir is dist/server/ssr.\n // We always want dist/server as the manifest location.\n if (!outDir) {\n // The server bundle outputs to dist/server for all environments except\n // App Router SSR, which outputs to dist/server/ssr. We always want\n // dist/server as the manifest location. Rather than hard-coding \"ssr\",\n // treat any sub-directory of dist/server (basename !== \"server\") as a\n // sub-env and walk up one level. This handles any future sub-directory\n // environments (e.g. \"edge\") without code changes.\n // Note: using basename rather than a walk-up avoids misfiring when a\n // user's project path contains a \"server\" segment above the dist output\n // (e.g. /home/user/server/my-app/).\n outDir = path.basename(dir) === \"server\" ? dir : path.dirname(dir);\n }\n\n const bundleFiles = new Set(Object.keys(bundle));\n for (const item of Object.values(bundle)) {\n if (item.type !== \"chunk\") continue;\n // In Rollup output, item.imports normally contains filenames of other\n // chunks in the bundle. But externalized packages remain as bare npm\n // specifiers (e.g. \"react\", \"@mdx-js/react\") since they were never\n // bundled into chunk files. packageNameFromSpecifier filters out chunk\n // filenames (relative/absolute paths) and extracts the package name from\n // bare specifiers — which is exactly what the standalone BFS needs.\n for (const specifier of [...item.imports, ...item.dynamicImports]) {\n if (bundleFiles.has(specifier)) {\n continue;\n }\n const pkg = packageNameFromSpecifier(specifier);\n if (pkg) externals.add(pkg);\n }\n }\n\n // After the last expected writeBundle call, flush to disk.\n // We flush on every call since we don't know ahead of time how many\n // environments will fire — overwriting with the accumulated set is safe.\n if (outDir && fs.existsSync(outDir)) {\n const manifestPath = path.join(outDir, \"vinext-externals.json\");\n fs.writeFileSync(manifestPath, JSON.stringify([...externals], null, 2) + \"\\n\", \"utf-8\");\n }\n },\n },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AAO3B,UAAK,MAAM,aAAa,CAAC,GAAG,KAAK,SAAS,GAAG,KAAK,eAAe,EAAE;AACjE,UAAI,YAAY,IAAI,UAAU,CAC5B;MAEF,MAAM,MAAM,yBAAyB,UAAU;AAC/C,UAAI,IAAK,WAAU,IAAI,IAAI;;;AAO/B,QAAI,UAAU,GAAG,WAAW,OAAO,EAAE;KACnC,MAAM,eAAe,KAAK,KAAK,QAAQ,wBAAwB;AAC/D,QAAG,cAAc,cAAc,KAAK,UAAU,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,QAAQ;;;GAG5F;EACF"}
@@ -22,13 +22,21 @@ type ParallelSlot = {
22
22
  * necessarily the innermost layout. -1 means "innermost" (legacy default).
23
23
  */
24
24
  layoutIndex: number;
25
+ /**
26
+ * Filesystem segments from the slot's root directory to its active page.
27
+ * Used at render time to compute segments for useSelectedLayoutSegment(slotName).
28
+ * For a page at the slot root (@team/page.tsx), this is [].
29
+ * For a sub-page (@team/members/page.tsx), this is ["members"].
30
+ * null when the slot has no active page (showing default.tsx fallback).
31
+ */
32
+ routeSegments: string[] | null;
25
33
  };
26
34
  type AppRoute = {
27
35
  /** URL pattern, e.g. "/" or "/about" or "/blog/:slug" */pattern: string; /** Absolute file path to the page component */
28
36
  pagePath: string | null; /** Absolute file path to the route handler (route.ts) */
29
37
  routePath: string | null; /** Ordered list of layout files from root to leaf */
30
- layouts: string[]; /** Ordered list of template files from root to leaf (parallel to layouts) */
31
- templates: string[]; /** Parallel route slots (from @slot directories at the route's directory level) */
38
+ layouts: string[]; /** Template files aligned with layouts array (null where no template exists at that level) */
39
+ templates: (string | null)[]; /** Parallel route slots (from @slot directories at the route's directory level) */
32
40
  parallelSlots: ParallelSlot[]; /** Loading component path */
33
41
  loadingPath: string | null; /** Error component path (leaf directory only) */
34
42
  errorPath: string | null;
@@ -48,7 +48,7 @@ async function appRouter(appDir, pageExtensions, matcher) {
48
48
  const slotSubRoutes = discoverSlotSubRoutes(routes, appDir, matcher);
49
49
  routes.push(...slotSubRoutes);
50
50
  validateRoutePatterns(routes.map((route) => route.pattern));
51
- validateRoutePatterns(routes.flatMap((route) => route.parallelSlots.flatMap((slot) => slot.interceptingRoutes.map((intercept) => intercept.targetPattern))));
51
+ validateRoutePatterns([...new Set(routes.flatMap((route) => route.parallelSlots.flatMap((slot) => slot.interceptingRoutes.map((intercept) => intercept.targetPattern))))]);
52
52
  routes.sort(compareRoutes);
53
53
  cachedRoutes = routes;
54
54
  cachedAppDir = appDir;
@@ -70,11 +70,16 @@ function discoverSlotSubRoutes(routes, _appDir, matcher) {
70
70
  const syntheticRoutes = [];
71
71
  const routesByPattern = new Map(routes.map((r) => [r.pattern, r]));
72
72
  const slotKey = (slotName, ownerDir) => `${slotName}\u0000${ownerDir}`;
73
- const applySlotSubPages = (route, slotPages) => {
74
- route.parallelSlots = route.parallelSlots.map((slot) => ({
75
- ...slot,
76
- pagePath: slotPages.get(slotKey(slot.name, slot.ownerDir)) ?? slot.pagePath
77
- }));
73
+ const applySlotSubPages = (route, slotPages, rawSegments) => {
74
+ route.parallelSlots = route.parallelSlots.map((slot) => {
75
+ const subPage = slotPages.get(slotKey(slot.name, slot.ownerDir));
76
+ if (subPage !== void 0) return {
77
+ ...slot,
78
+ pagePath: subPage,
79
+ routeSegments: rawSegments
80
+ };
81
+ return slot;
82
+ });
78
83
  };
79
84
  for (const parentRoute of routes) {
80
85
  if (parentRoute.parallelSlots.length === 0) continue;
@@ -118,13 +123,17 @@ function discoverSlotSubRoutes(routes, _appDir, matcher) {
118
123
  const existingRoute = routesByPattern.get(pattern);
119
124
  if (existingRoute) {
120
125
  if (existingRoute.routePath && !existingRoute.pagePath) throw new Error(`You cannot have two routes that resolve to the same path ("${pattern}").`);
121
- applySlotSubPages(existingRoute, slotPages);
126
+ applySlotSubPages(existingRoute, slotPages, rawSegments);
122
127
  continue;
123
128
  }
124
- const subSlots = parentRoute.parallelSlots.map((slot) => ({
125
- ...slot,
126
- pagePath: slotPages.get(slotKey(slot.name, slot.ownerDir)) || null
127
- }));
129
+ const subSlots = parentRoute.parallelSlots.map((slot) => {
130
+ const subPage = slotPages.get(slotKey(slot.name, slot.ownerDir));
131
+ return {
132
+ ...slot,
133
+ pagePath: subPage || null,
134
+ routeSegments: subPage ? rawSegments : null
135
+ };
136
+ });
128
137
  const newRoute = {
129
138
  pattern,
130
139
  pagePath: childrenDefault,
@@ -196,7 +205,7 @@ function fileToAppRoute(file, appDir, type, matcher) {
196
205
  isDynamic = routeIsDynamic;
197
206
  const pattern = "/" + urlSegments.join("/");
198
207
  const layouts = discoverLayouts(segments, appDir, matcher);
199
- const templates = discoverTemplates(segments, appDir, matcher);
208
+ const templates = discoverLayoutAlignedTemplates(segments, appDir, matcher);
200
209
  const layoutTreePositions = computeLayoutTreePositions(appDir, layouts);
201
210
  const layoutErrorPaths = discoverLayoutAlignedErrors(segments, appDir, matcher);
202
211
  const routeDir = dir === "." ? appDir : path.join(appDir, dir);
@@ -257,19 +266,23 @@ function discoverLayouts(segments, appDir, matcher) {
257
266
  return layouts;
258
267
  }
259
268
  /**
260
- * Discover all template files from root to the given directory.
261
- * Each level of the directory tree may have a template.tsx.
262
- * Templates are like layouts but re-mount on navigation.
269
+ * Discover template files aligned with the layouts array.
270
+ * Walks the same directory levels as discoverLayouts and, for each level
271
+ * that contributes a layout entry, checks whether template.tsx also exists.
272
+ * Returns an array of the same length as discoverLayouts() would return,
273
+ * with the template path (or null) at each corresponding layout level.
274
+ *
275
+ * This enables interleaving templates with their corresponding layouts,
276
+ * matching Next.js behavior where each segment's hierarchy is
277
+ * Layout > Template > ErrorBoundary > children.
263
278
  */
264
- function discoverTemplates(segments, appDir, matcher) {
279
+ function discoverLayoutAlignedTemplates(segments, appDir, matcher) {
265
280
  const templates = [];
266
- const rootTemplate = findFile(appDir, "template", matcher);
267
- if (rootTemplate) templates.push(rootTemplate);
281
+ if (findFile(appDir, "layout", matcher)) templates.push(findFile(appDir, "template", matcher));
268
282
  let currentDir = appDir;
269
283
  for (const segment of segments) {
270
284
  currentDir = path.join(currentDir, segment);
271
- const template = findFile(currentDir, "template", matcher);
272
- if (template) templates.push(template);
285
+ if (findFile(currentDir, "layout", matcher)) templates.push(findFile(currentDir, "template", matcher));
273
286
  }
274
287
  return templates;
275
288
  }
@@ -366,7 +379,8 @@ function discoverInheritedParallelSlots(segments, appDir, routeDir, matcher) {
366
379
  const inheritedSlot = {
367
380
  ...slot,
368
381
  pagePath: null,
369
- layoutIndex: lvlLayoutIdx
382
+ layoutIndex: lvlLayoutIdx,
383
+ routeSegments: null
370
384
  };
371
385
  slotMap.set(slot.name, inheritedSlot);
372
386
  }
@@ -398,7 +412,8 @@ function discoverParallelSlots(dir, appDir, matcher) {
398
412
  loadingPath: findFile(slotDir, "loading", matcher),
399
413
  errorPath: findFile(slotDir, "error", matcher),
400
414
  interceptingRoutes,
401
- layoutIndex: -1
415
+ layoutIndex: -1,
416
+ routeSegments: pagePath ? [] : null
402
417
  });
403
418
  }
404
419
  return slots;
@@ -1 +1 @@
1
- {"version":3,"file":"app-router.js","names":[],"sources":["../../src/routing/app-router.ts"],"sourcesContent":["/**\n * App Router file-system routing.\n *\n * Scans the app/ directory following Next.js App Router conventions:\n * - app/page.tsx -> /\n * - app/about/page.tsx -> /about\n * - app/blog/[slug]/page.tsx -> /blog/:slug\n * - app/[...catchAll]/page.tsx -> /:catchAll+\n * - app/route.ts -> / (API route)\n * - app/(group)/page.tsx -> / (route groups are transparent)\n * - Layouts: app/layout.tsx wraps all children\n * - Loading: app/loading.tsx -> Suspense fallback\n * - Error: app/error.tsx -> ErrorBoundary\n * - Not Found: app/not-found.tsx\n */\nimport path from \"node:path\";\nimport fs from \"node:fs\";\nimport { compareRoutes, decodeRouteSegment, normalizePathnameForRouteMatch } from \"./utils.js\";\nimport {\n createValidFileMatcher,\n scanWithExtensions,\n type ValidFileMatcher,\n} from \"./file-matcher.js\";\nimport { validateRoutePatterns } from \"./route-validation.js\";\nimport { buildRouteTrie, trieMatch, type TrieNode } from \"./route-trie.js\";\n\nexport type InterceptingRoute = {\n /** The interception convention: \".\" | \"..\" | \"../..\" | \"...\" */\n convention: string;\n /** The URL pattern this intercepts (e.g. \"/photos/:id\") */\n targetPattern: string;\n /** Absolute path to the intercepting page component */\n pagePath: string;\n /** Parameter names for dynamic segments */\n params: string[];\n};\n\nexport type ParallelSlot = {\n /** Slot name (e.g. \"team\" from @team) */\n name: string;\n /** Absolute path to the @slot directory that owns this slot. Internal routing metadata. */\n ownerDir: string;\n /** Absolute path to the slot's page component */\n pagePath: string | null;\n /** Absolute path to the slot's default.tsx fallback */\n defaultPath: string | null;\n /** Absolute path to the slot's layout component (wraps slot content) */\n layoutPath: string | null;\n /** Absolute path to the slot's loading component */\n loadingPath: string | null;\n /** Absolute path to the slot's error component */\n errorPath: string | null;\n /** Intercepting routes within this slot */\n interceptingRoutes: InterceptingRoute[];\n /**\n * The layout index (0-based, in route.layouts[]) that this slot belongs to.\n * Slots are passed as props to the layout at their directory level, not\n * necessarily the innermost layout. -1 means \"innermost\" (legacy default).\n */\n layoutIndex: number;\n};\n\nexport type AppRoute = {\n /** URL pattern, e.g. \"/\" or \"/about\" or \"/blog/:slug\" */\n pattern: string;\n /** Absolute file path to the page component */\n pagePath: string | null;\n /** Absolute file path to the route handler (route.ts) */\n routePath: string | null;\n /** Ordered list of layout files from root to leaf */\n layouts: string[];\n /** Ordered list of template files from root to leaf (parallel to layouts) */\n templates: string[];\n /** Parallel route slots (from @slot directories at the route's directory level) */\n parallelSlots: ParallelSlot[];\n /** Loading component path */\n loadingPath: string | null;\n /** Error component path (leaf directory only) */\n errorPath: string | null;\n /**\n * Per-layout error boundary paths, aligned with the layouts array.\n * Each entry is the error.tsx at the same directory level as the\n * corresponding layout (or null if that level has no error.tsx).\n * Used to interleave ErrorBoundary components with layouts so that\n * ancestor error boundaries catch errors from descendant segments.\n */\n layoutErrorPaths: (string | null)[];\n /** Not-found component path (nearest, walking up from page dir) */\n notFoundPath: string | null;\n /**\n * Not-found component paths per layout level (aligned with layouts array).\n * Each entry is the not-found.tsx at that layout's directory, or null.\n * Used to create per-layout NotFoundBoundary so that notFound() thrown from\n * a layout is caught by the parent layout's boundary (matching Next.js behavior).\n */\n notFoundPaths: (string | null)[];\n /** Forbidden component path (403) */\n forbiddenPath: string | null;\n /** Unauthorized component path (401) */\n unauthorizedPath: string | null;\n /**\n * Filesystem segments from app/ root to the route's directory.\n * Includes route groups and dynamic segments (as template strings like \"[id]\").\n * Used at render time to compute the child segments for useSelectedLayoutSegments().\n */\n routeSegments: string[];\n /**\n * Tree position (directory depth from app/ root) for each layout.\n * Used to slice routeSegments and determine which segments are below each layout.\n * For example, root layout = 0, a layout at app/blog/ = 1, app/blog/(group)/ = 2.\n * Unlike the old layoutSegmentDepths, this counts ALL directory levels including\n * route groups and parallel slots.\n */\n layoutTreePositions: number[];\n /** Whether this is a dynamic route */\n isDynamic: boolean;\n /** Parameter names for dynamic segments */\n params: string[];\n /** Pre-split pattern segments (computed once at scan time, reused per request) */\n patternParts: string[];\n};\n\n// Cache for app routes\nlet cachedRoutes: AppRoute[] | null = null;\nlet cachedAppDir: string | null = null;\nlet cachedPageExtensionsKey: string | null = null;\n\nexport function invalidateAppRouteCache(): void {\n cachedRoutes = null;\n cachedAppDir = null;\n cachedPageExtensionsKey = null;\n}\n\n/**\n * Scan the app/ directory and return a list of routes.\n */\nexport async function appRouter(\n appDir: string,\n pageExtensions?: readonly string[],\n matcher?: ValidFileMatcher,\n): Promise<AppRoute[]> {\n matcher ??= createValidFileMatcher(pageExtensions);\n const pageExtensionsKey = JSON.stringify(matcher.extensions);\n if (cachedRoutes && cachedAppDir === appDir && cachedPageExtensionsKey === pageExtensionsKey) {\n return cachedRoutes;\n }\n\n // Find all page.tsx and route.ts files, excluding @slot directories\n // (slot pages are not standalone routes — they're rendered as props of their parent layout)\n // and _private folders (Next.js convention for colocated non-route files).\n const routes: AppRoute[] = [];\n\n const excludeDir = (name: string) => name.startsWith(\"@\") || name.startsWith(\"_\");\n\n // Process page files in a single pass\n // Use function form of exclude for Node < 22.14 compatibility (string arrays require >= 22.14)\n for await (const file of scanWithExtensions(\"**/page\", appDir, matcher.extensions, excludeDir)) {\n const route = fileToAppRoute(file, appDir, \"page\", matcher);\n if (route) routes.push(route);\n }\n\n // Process route handler files (API routes) in a single pass\n for await (const file of scanWithExtensions(\"**/route\", appDir, matcher.extensions, excludeDir)) {\n const route = fileToAppRoute(file, appDir, \"route\", matcher);\n if (route) routes.push(route);\n }\n\n // Discover sub-routes created by nested pages within parallel slots.\n // In Next.js, pages nested inside @slot directories create additional URL routes.\n // For example, @audience/demographics/page.tsx at app/parallel-routes/ creates\n // a route at /parallel-routes/demographics.\n const slotSubRoutes = discoverSlotSubRoutes(routes, appDir, matcher);\n routes.push(...slotSubRoutes);\n\n validateRoutePatterns(routes.map((route) => route.pattern));\n validateRoutePatterns(\n routes.flatMap((route) =>\n route.parallelSlots.flatMap((slot) =>\n slot.interceptingRoutes.map((intercept) => intercept.targetPattern),\n ),\n ),\n );\n\n // Sort: static routes first, then dynamic, then catch-all\n routes.sort(compareRoutes);\n\n cachedRoutes = routes;\n cachedAppDir = appDir;\n cachedPageExtensionsKey = pageExtensionsKey;\n return routes;\n}\n\n/**\n * Discover sub-routes created by nested pages within parallel slots.\n *\n * In Next.js, pages nested inside @slot directories create additional URL routes.\n * For example, given:\n * app/parallel-routes/@audience/demographics/page.tsx\n * This creates a route at /parallel-routes/demographics where:\n * - children slot → parent's default.tsx\n * - @audience slot → @audience/demographics/page.tsx (matched)\n * - other slots → their default.tsx (fallback)\n */\nfunction discoverSlotSubRoutes(\n routes: AppRoute[],\n _appDir: string,\n matcher: ValidFileMatcher,\n): AppRoute[] {\n const syntheticRoutes: AppRoute[] = [];\n\n // O(1) lookup for existing routes by pattern — avoids O(n) routes.find() per sub-path per parent.\n // Updated as new synthetic routes are pushed so that later parents can see earlier synthetic entries.\n const routesByPattern = new Map<string, AppRoute>(routes.map((r) => [r.pattern, r]));\n\n const slotKey = (slotName: string, ownerDir: string): string => `${slotName}\\u0000${ownerDir}`;\n\n const applySlotSubPages = (route: AppRoute, slotPages: Map<string, string>): void => {\n route.parallelSlots = route.parallelSlots.map((slot) => ({\n ...slot,\n pagePath: slotPages.get(slotKey(slot.name, slot.ownerDir)) ?? slot.pagePath,\n }));\n };\n\n for (const parentRoute of routes) {\n if (parentRoute.parallelSlots.length === 0) continue;\n if (!parentRoute.pagePath) continue;\n\n const parentPageDir = path.dirname(parentRoute.pagePath);\n\n // Collect sub-paths from all slots.\n // Map: normalized visible sub-path -> slot pages, raw filesystem segments (for routeSegments),\n // and the pre-computed convertedSubRoute (to avoid a redundant re-conversion in the merge loop).\n const subPathMap = new Map<\n string,\n {\n // Raw filesystem segments (with route groups, @slots, etc.) used for routeSegments so\n // that useSelectedLayoutSegments() sees the correct segment list at runtime.\n rawSegments: string[];\n // Pre-computed URL parts, params, isDynamic from convertSegmentsToRouteParts.\n converted: { urlSegments: string[]; params: string[]; isDynamic: boolean };\n slotPages: Map<string, string>;\n }\n >();\n\n for (const slot of parentRoute.parallelSlots) {\n const slotDir = path.join(parentPageDir, `@${slot.name}`);\n if (!fs.existsSync(slotDir)) continue;\n\n const subPages = findSlotSubPages(slotDir, matcher);\n for (const { relativePath, pagePath } of subPages) {\n const subSegments = relativePath.split(path.sep);\n const convertedSubRoute = convertSegmentsToRouteParts(subSegments);\n if (!convertedSubRoute) continue;\n\n const { urlSegments } = convertedSubRoute;\n const normalizedSubPath = urlSegments.join(\"/\");\n let subPathEntry = subPathMap.get(normalizedSubPath);\n\n if (!subPathEntry) {\n subPathEntry = {\n rawSegments: subSegments,\n converted: convertedSubRoute,\n slotPages: new Map(),\n };\n subPathMap.set(normalizedSubPath, subPathEntry);\n }\n\n const slotId = slotKey(slot.name, slot.ownerDir);\n const existingSlotPage = subPathEntry.slotPages.get(slotId);\n if (existingSlotPage) {\n const pattern = joinRoutePattern(parentRoute.pattern, normalizedSubPath);\n throw new Error(\n `You cannot have two routes that resolve to the same path (\"${pattern}\").`,\n );\n }\n\n subPathEntry.slotPages.set(slotId, pagePath);\n }\n }\n\n if (subPathMap.size === 0) continue;\n\n // Find the default.tsx for the children slot at the parent directory\n const childrenDefault = findFile(parentPageDir, \"default\", matcher);\n if (!childrenDefault) continue;\n\n for (const { rawSegments, converted: convertedSubRoute, slotPages } of subPathMap.values()) {\n const {\n urlSegments: urlParts,\n params: subParams,\n isDynamic: subIsDynamic,\n } = convertedSubRoute;\n\n const subUrlPath = urlParts.join(\"/\");\n const pattern = joinRoutePattern(parentRoute.pattern, subUrlPath);\n\n const existingRoute = routesByPattern.get(pattern);\n if (existingRoute) {\n if (existingRoute.routePath && !existingRoute.pagePath) {\n throw new Error(\n `You cannot have two routes that resolve to the same path (\"${pattern}\").`,\n );\n }\n applySlotSubPages(existingRoute, slotPages);\n continue;\n }\n\n // Build parallel slots for this sub-route: matching slots get the sub-page,\n // non-matching slots get null pagePath (rendering falls back to defaultPath)\n const subSlots: ParallelSlot[] = parentRoute.parallelSlots.map((slot) => ({\n ...slot,\n pagePath: slotPages.get(slotKey(slot.name, slot.ownerDir)) || null,\n }));\n\n const newRoute: AppRoute = {\n pattern,\n pagePath: childrenDefault, // children slot uses parent's default.tsx as page\n routePath: null,\n layouts: parentRoute.layouts,\n templates: parentRoute.templates,\n parallelSlots: subSlots,\n loadingPath: parentRoute.loadingPath,\n errorPath: parentRoute.errorPath,\n layoutErrorPaths: parentRoute.layoutErrorPaths,\n notFoundPath: parentRoute.notFoundPath,\n notFoundPaths: parentRoute.notFoundPaths,\n forbiddenPath: parentRoute.forbiddenPath,\n unauthorizedPath: parentRoute.unauthorizedPath,\n routeSegments: [...parentRoute.routeSegments, ...rawSegments],\n layoutTreePositions: parentRoute.layoutTreePositions,\n isDynamic: parentRoute.isDynamic || subIsDynamic,\n params: [...parentRoute.params, ...subParams],\n patternParts: [...parentRoute.patternParts, ...urlParts],\n };\n syntheticRoutes.push(newRoute);\n routesByPattern.set(pattern, newRoute);\n }\n }\n\n return syntheticRoutes;\n}\n\n/**\n * Find all page files in subdirectories of a parallel slot directory.\n * Returns relative paths (from the slot dir) and absolute page paths.\n * Skips the root page.tsx (already handled as the slot's main page)\n * and intercepting route directories.\n */\nfunction findSlotSubPages(\n slotDir: string,\n matcher: ValidFileMatcher,\n): Array<{ relativePath: string; pagePath: string }> {\n const results: Array<{ relativePath: string; pagePath: string }> = [];\n\n function scan(dir: string): void {\n if (!fs.existsSync(dir)) return;\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n // Skip intercepting route directories\n if (matchInterceptConvention(entry.name)) continue;\n // Skip private folders (prefixed with _)\n if (entry.name.startsWith(\"_\")) continue;\n\n const subDir = path.join(dir, entry.name);\n const page = findFile(subDir, \"page\", matcher);\n if (page) {\n const relativePath = path.relative(slotDir, subDir);\n results.push({ relativePath, pagePath: page });\n }\n // Continue scanning deeper for nested sub-pages\n scan(subDir);\n }\n }\n\n scan(slotDir);\n return results;\n}\n\n/**\n * Convert a file path relative to app/ into an AppRoute.\n */\nfunction fileToAppRoute(\n file: string,\n appDir: string,\n type: \"page\" | \"route\",\n matcher: ValidFileMatcher,\n): AppRoute | null {\n // Remove the filename (page.tsx or route.ts)\n const dir = path.dirname(file);\n const segments = dir === \".\" ? [] : dir.split(path.sep);\n\n const params: string[] = [];\n let isDynamic = false;\n\n const convertedRoute = convertSegmentsToRouteParts(segments);\n if (!convertedRoute) return null;\n\n const { urlSegments, params: routeParams, isDynamic: routeIsDynamic } = convertedRoute;\n params.push(...routeParams);\n isDynamic = routeIsDynamic;\n\n const pattern = \"/\" + urlSegments.join(\"/\");\n\n // Discover layouts and templates from root to leaf\n const layouts = discoverLayouts(segments, appDir, matcher);\n const templates = discoverTemplates(segments, appDir, matcher);\n\n // Compute the tree position (directory depth) for each layout.\n const layoutTreePositions = computeLayoutTreePositions(appDir, layouts);\n\n // Discover per-layout error boundaries (aligned with layouts array).\n // In Next.js, each segment independently wraps its children with an ErrorBoundary.\n // This array enables interleaving error boundaries with layouts in the rendering.\n const layoutErrorPaths = discoverLayoutAlignedErrors(segments, appDir, matcher);\n\n // Discover loading, error in the route's directory\n const routeDir = dir === \".\" ? appDir : path.join(appDir, dir);\n const loadingPath = findFile(routeDir, \"loading\", matcher);\n const errorPath = findFile(routeDir, \"error\", matcher);\n\n // Discover not-found/forbidden/unauthorized: walk from route directory up to root (nearest wins).\n const notFoundPath = discoverBoundaryFile(segments, appDir, \"not-found\", matcher);\n const forbiddenPath = discoverBoundaryFile(segments, appDir, \"forbidden\", matcher);\n const unauthorizedPath = discoverBoundaryFile(segments, appDir, \"unauthorized\", matcher);\n\n // Discover per-layout not-found files (one per layout directory).\n // These are used for per-layout NotFoundBoundary to match Next.js behavior where\n // notFound() thrown from a layout is caught by the parent layout's boundary.\n const notFoundPaths = discoverBoundaryFilePerLayout(layouts, \"not-found\", matcher);\n\n // Discover parallel slots (@team, @analytics, etc.).\n // Slots at the route's own directory use page.tsx; slots at ancestor directories\n // (inherited from parent layouts) use default.tsx as fallback.\n const parallelSlots = discoverInheritedParallelSlots(segments, appDir, routeDir, matcher);\n\n return {\n pattern: pattern === \"/\" ? \"/\" : pattern,\n pagePath: type === \"page\" ? path.join(appDir, file) : null,\n routePath: type === \"route\" ? path.join(appDir, file) : null,\n layouts,\n templates,\n parallelSlots,\n loadingPath,\n errorPath,\n layoutErrorPaths,\n notFoundPath,\n notFoundPaths,\n forbiddenPath,\n unauthorizedPath,\n routeSegments: segments,\n layoutTreePositions,\n isDynamic,\n params,\n patternParts: urlSegments,\n };\n}\n\n/**\n * Compute the tree position (directory depth from app root) for each layout.\n * Root layout = 0, a layout at app/blog/ = 1, app/blog/(group)/ = 2.\n * Counts ALL directory levels including route groups and parallel slots.\n */\nfunction computeLayoutTreePositions(appDir: string, layouts: string[]): number[] {\n return layouts.map((layoutPath) => {\n const layoutDir = path.dirname(layoutPath);\n if (layoutDir === appDir) return 0;\n const relative = path.relative(appDir, layoutDir);\n return relative.split(path.sep).length;\n });\n}\n\n/**\n * Discover all layout files from root to the given directory.\n * Each level of the directory tree may have a layout.tsx.\n */\nfunction discoverLayouts(segments: string[], appDir: string, matcher: ValidFileMatcher): string[] {\n const layouts: string[] = [];\n\n // Check root layout\n const rootLayout = findFile(appDir, \"layout\", matcher);\n if (rootLayout) layouts.push(rootLayout);\n\n // Check each directory level\n let currentDir = appDir;\n for (const segment of segments) {\n currentDir = path.join(currentDir, segment);\n const layout = findFile(currentDir, \"layout\", matcher);\n if (layout) layouts.push(layout);\n }\n\n return layouts;\n}\n\n/**\n * Discover all template files from root to the given directory.\n * Each level of the directory tree may have a template.tsx.\n * Templates are like layouts but re-mount on navigation.\n */\nfunction discoverTemplates(\n segments: string[],\n appDir: string,\n matcher: ValidFileMatcher,\n): string[] {\n const templates: string[] = [];\n\n // Check root template\n const rootTemplate = findFile(appDir, \"template\", matcher);\n if (rootTemplate) templates.push(rootTemplate);\n\n // Check each directory level\n let currentDir = appDir;\n for (const segment of segments) {\n currentDir = path.join(currentDir, segment);\n const template = findFile(currentDir, \"template\", matcher);\n if (template) templates.push(template);\n }\n\n return templates;\n}\n\n/**\n * Discover error.tsx files aligned with the layouts array.\n * Walks the same directory levels as discoverLayouts and, for each level\n * that contributes a layout entry, checks whether error.tsx also exists.\n * Returns an array of the same length as discoverLayouts() would return,\n * with the error path (or null) at each corresponding layout level.\n *\n * This enables interleaving ErrorBoundary components with layouts in the\n * rendering tree, matching Next.js behavior where each segment independently\n * wraps its children with an error boundary.\n */\nfunction discoverLayoutAlignedErrors(\n segments: string[],\n appDir: string,\n matcher: ValidFileMatcher,\n): (string | null)[] {\n const errors: (string | null)[] = [];\n\n // Root level (only if root has a layout — matching discoverLayouts logic)\n const rootLayout = findFile(appDir, \"layout\", matcher);\n if (rootLayout) {\n errors.push(findFile(appDir, \"error\", matcher));\n }\n\n // Check each directory level\n let currentDir = appDir;\n for (const segment of segments) {\n currentDir = path.join(currentDir, segment);\n const layout = findFile(currentDir, \"layout\", matcher);\n if (layout) {\n errors.push(findFile(currentDir, \"error\", matcher));\n }\n }\n\n return errors;\n}\n\n/**\n * Discover the nearest boundary file (not-found, forbidden, unauthorized)\n * by walking from the route's directory up to the app root.\n * Returns the first (closest) file found, or null.\n */\nfunction discoverBoundaryFile(\n segments: string[],\n appDir: string,\n fileName: string,\n matcher: ValidFileMatcher,\n): string | null {\n // Build all directory paths from leaf to root\n const dirs: string[] = [];\n let dir = appDir;\n dirs.push(dir);\n for (const segment of segments) {\n dir = path.join(dir, segment);\n dirs.push(dir);\n }\n\n // Walk from leaf (last) to root (first)\n for (let i = dirs.length - 1; i >= 0; i--) {\n const f = findFile(dirs[i], fileName, matcher);\n if (f) return f;\n }\n return null;\n}\n\n/**\n * Discover boundary files (not-found, forbidden, unauthorized) at each layout directory.\n * Returns an array aligned with the layouts array, where each entry is the boundary\n * file at that layout's directory, or null if none exists there.\n *\n * This is used for per-layout error boundaries. In Next.js, each layout level\n * has its own boundary that wraps the layout's children. When notFound() is thrown\n * from a layout, it propagates up to the parent layout's boundary.\n */\nfunction discoverBoundaryFilePerLayout(\n layouts: string[],\n fileName: string,\n matcher: ValidFileMatcher,\n): (string | null)[] {\n return layouts.map((layoutPath) => {\n const layoutDir = path.dirname(layoutPath);\n return findFile(layoutDir, fileName, matcher);\n });\n}\n\n/**\n * Discover parallel slots inherited from ancestor directories.\n *\n * In Next.js, parallel slots belong to the layout that defines them. When a\n * child route is rendered, its parent layout's slots must still be present.\n * If the child doesn't have matching content in a slot, the slot's default.tsx\n * is rendered instead.\n *\n * Walk from appDir through each segment to the route's directory. At each level\n * that has @slot dirs, collect them. Slots at the route's own directory level\n * use page.tsx; slots at ancestor levels use default.tsx only.\n */\nfunction discoverInheritedParallelSlots(\n segments: string[],\n appDir: string,\n routeDir: string,\n matcher: ValidFileMatcher,\n): ParallelSlot[] {\n const slotMap = new Map<string, ParallelSlot>();\n\n // Walk from appDir through each segment, tracking layout indices.\n // layoutIndex tracks which position in the route's layouts[] array corresponds\n // to a given directory. Only directories with a layout.tsx file increment.\n let currentDir = appDir;\n const dirsToCheck: { dir: string; layoutIdx: number }[] = [];\n let layoutIdx = findFile(appDir, \"layout\", matcher) ? 0 : -1;\n dirsToCheck.push({ dir: appDir, layoutIdx: Math.max(layoutIdx, 0) });\n\n for (const segment of segments) {\n currentDir = path.join(currentDir, segment);\n if (findFile(currentDir, \"layout\", matcher)) {\n layoutIdx++;\n }\n dirsToCheck.push({ dir: currentDir, layoutIdx: Math.max(layoutIdx, 0) });\n }\n\n for (const { dir, layoutIdx: lvlLayoutIdx } of dirsToCheck) {\n const isOwnDir = dir === routeDir;\n const slotsAtLevel = discoverParallelSlots(dir, appDir, matcher);\n\n for (const slot of slotsAtLevel) {\n if (isOwnDir) {\n // At the route's own directory: use page.tsx (normal behavior)\n slot.layoutIndex = lvlLayoutIdx;\n slotMap.set(slot.name, slot);\n } else {\n // At an ancestor directory: use default.tsx as the page, not page.tsx\n // (the slot's page.tsx is for the parent route, not this child route)\n const inheritedSlot: ParallelSlot = {\n ...slot,\n pagePath: null, // Don't use ancestor's page.tsx\n layoutIndex: lvlLayoutIdx,\n // defaultPath, loadingPath, errorPath, interceptingRoutes remain\n };\n // Iteration goes root-to-leaf, so later (closer) ancestors overwrite\n // earlier (farther) ones — the closest ancestor's slot wins.\n slotMap.set(slot.name, inheritedSlot);\n }\n }\n }\n\n return Array.from(slotMap.values());\n}\n\n/**\n * Discover parallel route slots (@team, @analytics, etc.) in a directory.\n * Returns a ParallelSlot for each @-prefixed subdirectory that has a page or default component.\n */\nfunction discoverParallelSlots(\n dir: string,\n appDir: string,\n matcher: ValidFileMatcher,\n): ParallelSlot[] {\n if (!fs.existsSync(dir)) return [];\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n const slots: ParallelSlot[] = [];\n\n for (const entry of entries) {\n if (!entry.isDirectory() || !entry.name.startsWith(\"@\")) continue;\n\n const slotName = entry.name.slice(1); // \"@team\" -> \"team\"\n const slotDir = path.join(dir, entry.name);\n\n const pagePath = findFile(slotDir, \"page\", matcher);\n const defaultPath = findFile(slotDir, \"default\", matcher);\n const interceptingRoutes = discoverInterceptingRoutes(slotDir, dir, appDir, matcher);\n\n // Only include slots that have at least a page, default, or intercepting route\n if (!pagePath && !defaultPath && interceptingRoutes.length === 0) continue;\n\n slots.push({\n name: slotName,\n ownerDir: slotDir,\n pagePath,\n defaultPath,\n layoutPath: findFile(slotDir, \"layout\", matcher),\n loadingPath: findFile(slotDir, \"loading\", matcher),\n errorPath: findFile(slotDir, \"error\", matcher),\n interceptingRoutes,\n layoutIndex: -1, // Will be set by discoverInheritedParallelSlots\n });\n }\n\n return slots;\n}\n\n/**\n * The interception convention prefix patterns.\n * (.) — same level, (..) — one level up, (..)(..)\" — two levels up, (...) — root\n */\nconst INTERCEPT_PATTERNS = [\n { prefix: \"(...)\", convention: \"...\" },\n { prefix: \"(..)(..)\", convention: \"../..\" },\n { prefix: \"(..)\", convention: \"..\" },\n { prefix: \"(.)\", convention: \".\" },\n] as const;\n\n/**\n * Discover intercepting routes inside a parallel slot directory.\n *\n * Intercepting routes use conventions like (.)photo, (..)feed, (...), etc.\n * They intercept navigation to another route and render within the slot instead.\n *\n * @param slotDir - The parallel slot directory (e.g. app/feed/@modal)\n * @param routeDir - The directory of the route that owns this slot (e.g. app/feed)\n * @param appDir - The root app directory\n */\nfunction discoverInterceptingRoutes(\n slotDir: string,\n routeDir: string,\n appDir: string,\n matcher: ValidFileMatcher,\n): InterceptingRoute[] {\n if (!fs.existsSync(slotDir)) return [];\n\n const results: InterceptingRoute[] = [];\n\n // Recursively scan for page files inside intercepting directories\n scanForInterceptingPages(slotDir, routeDir, appDir, results, matcher);\n\n return results;\n}\n\n/**\n * Recursively scan a directory tree for page.tsx files that are inside\n * intercepting route directories.\n */\nfunction scanForInterceptingPages(\n currentDir: string,\n routeDir: string,\n appDir: string,\n results: InterceptingRoute[],\n matcher: ValidFileMatcher,\n): void {\n if (!fs.existsSync(currentDir)) return;\n\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\n\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n // Skip private folders (prefixed with _)\n if (entry.name.startsWith(\"_\")) continue;\n\n // Check if this directory name starts with an interception convention\n const interceptMatch = matchInterceptConvention(entry.name);\n\n if (interceptMatch) {\n // This directory is the start of an intercepting route\n // e.g. \"(.)photos\" means intercept same-level \"photos\" route\n const restOfName = entry.name.slice(interceptMatch.prefix.length);\n const interceptDir = path.join(currentDir, entry.name);\n\n // Find page files within this intercepting directory tree\n collectInterceptingPages(\n interceptDir,\n interceptDir,\n interceptMatch.convention,\n restOfName,\n routeDir,\n appDir,\n results,\n matcher,\n );\n } else {\n // Regular subdirectory — keep scanning for intercepting dirs\n scanForInterceptingPages(\n path.join(currentDir, entry.name),\n routeDir,\n appDir,\n results,\n matcher,\n );\n }\n }\n}\n\n/**\n * Match a directory name against interception convention prefixes.\n */\nfunction matchInterceptConvention(name: string): { prefix: string; convention: string } | null {\n for (const pattern of INTERCEPT_PATTERNS) {\n if (name.startsWith(pattern.prefix)) {\n return pattern;\n }\n }\n return null;\n}\n\n/**\n * Collect page.tsx files inside an intercepting route directory tree\n * and compute their target URL patterns.\n */\nfunction collectInterceptingPages(\n currentDir: string,\n interceptRoot: string,\n convention: string,\n interceptSegment: string,\n routeDir: string,\n appDir: string,\n results: InterceptingRoute[],\n matcher: ValidFileMatcher,\n): void {\n // Check for page.tsx in current directory\n const page = findFile(currentDir, \"page\", matcher);\n if (page) {\n const targetPattern = computeInterceptTarget(\n convention,\n interceptSegment,\n currentDir,\n interceptRoot,\n routeDir,\n appDir,\n );\n if (targetPattern) {\n results.push({\n convention,\n targetPattern: targetPattern.pattern,\n pagePath: page,\n params: targetPattern.params,\n });\n }\n }\n\n // Recurse into subdirectories for nested intercepting routes\n if (!fs.existsSync(currentDir)) return;\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n // Skip private folders (prefixed with _)\n if (entry.name.startsWith(\"_\")) continue;\n collectInterceptingPages(\n path.join(currentDir, entry.name),\n interceptRoot,\n convention,\n interceptSegment,\n routeDir,\n appDir,\n results,\n matcher,\n );\n }\n}\n\n/**\n * Check whether a path segment is invisible in the URL (route groups, parallel slots, \".\").\n *\n * Used by computeInterceptTarget, convertSegmentsToRouteParts, and\n * hasRemainingVisibleSegments — keep this the single source of truth.\n */\nfunction isInvisibleSegment(segment: string): boolean {\n if (segment === \".\") return true;\n if (segment.startsWith(\"(\") && segment.endsWith(\")\")) return true;\n if (segment.startsWith(\"@\")) return true;\n return false;\n}\n\n/**\n * Compute the target URL pattern for an intercepting route.\n *\n * Interception conventions (..), (..)(..)\" climb by *visible route segments*\n * (not filesystem directories). Route groups like (marketing) and parallel\n * slots like @modal are invisible and must be skipped when counting levels.\n *\n * - (.) same level: resolve relative to routeDir\n * - (..) one level up: climb 1 visible segment\n * - (..)(..) two levels up: climb 2 visible segments\n * - (...) root: resolve from appDir\n */\nfunction computeInterceptTarget(\n convention: string,\n interceptSegment: string,\n currentDir: string,\n interceptRoot: string,\n routeDir: string,\n appDir: string,\n): { pattern: string; params: string[] } | null {\n // Determine the base segments for target resolution.\n // We work on route segments (not filesystem paths) so that route groups\n // and parallel slots are properly skipped when climbing.\n const routeSegments = path.relative(appDir, routeDir).split(path.sep).filter(Boolean);\n\n let baseParts: string[];\n switch (convention) {\n case \".\":\n baseParts = routeSegments;\n break;\n case \"..\":\n case \"../..\": {\n const levelsToClimb = convention === \"..\" ? 1 : 2;\n let climbed = 0;\n let cutIndex = routeSegments.length;\n while (cutIndex > 0 && climbed < levelsToClimb) {\n cutIndex--;\n if (!isInvisibleSegment(routeSegments[cutIndex])) {\n climbed++;\n }\n }\n baseParts = routeSegments.slice(0, cutIndex);\n break;\n }\n case \"...\":\n baseParts = [];\n break;\n default:\n return null;\n }\n\n // Add the intercept segment and any nested path segments\n const nestedParts = path.relative(interceptRoot, currentDir).split(path.sep).filter(Boolean);\n const allSegments = [...baseParts, interceptSegment, ...nestedParts];\n\n const convertedTarget = convertSegmentsToRouteParts(allSegments);\n if (!convertedTarget) return null;\n\n const { urlSegments, params } = convertedTarget;\n\n const pattern = \"/\" + urlSegments.join(\"/\");\n return { pattern: pattern === \"/\" ? \"/\" : pattern, params };\n}\n\n/**\n * Find a file by name (without extension) in a directory.\n * Checks configured pageExtensions.\n */\nfunction findFile(dir: string, name: string, matcher: ValidFileMatcher): string | null {\n for (const ext of matcher.dottedExtensions) {\n const filePath = path.join(dir, name + ext);\n if (fs.existsSync(filePath)) return filePath;\n }\n return null;\n}\n\n/**\n * Convert filesystem path segments to URL route parts, skipping invisible segments\n * (route groups, @slots, \".\") and converting dynamic segment syntax to Express-style\n * patterns (e.g. \"[id]\" → \":id\", \"[...slug]\" → \":slug+\").\n */\nfunction convertSegmentsToRouteParts(\n segments: string[],\n): { urlSegments: string[]; params: string[]; isDynamic: boolean } | null {\n const urlSegments: string[] = [];\n const params: string[] = [];\n let isDynamic = false;\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i];\n\n if (isInvisibleSegment(segment)) continue;\n\n // Catch-all segments are only valid in terminal URL position.\n const catchAllMatch = segment.match(/^\\[\\.\\.\\.([\\w-]+)\\]$/);\n if (catchAllMatch) {\n if (hasRemainingVisibleSegments(segments, i + 1)) return null;\n isDynamic = true;\n params.push(catchAllMatch[1]);\n urlSegments.push(`:${catchAllMatch[1]}+`);\n continue;\n }\n\n const optionalCatchAllMatch = segment.match(/^\\[\\[\\.\\.\\.([\\w-]+)\\]\\]$/);\n if (optionalCatchAllMatch) {\n if (hasRemainingVisibleSegments(segments, i + 1)) return null;\n isDynamic = true;\n params.push(optionalCatchAllMatch[1]);\n urlSegments.push(`:${optionalCatchAllMatch[1]}*`);\n continue;\n }\n\n const dynamicMatch = segment.match(/^\\[([\\w-]+)\\]$/);\n if (dynamicMatch) {\n isDynamic = true;\n params.push(dynamicMatch[1]);\n urlSegments.push(`:${dynamicMatch[1]}`);\n continue;\n }\n\n urlSegments.push(decodeRouteSegment(segment));\n }\n\n return { urlSegments, params, isDynamic };\n}\n\nfunction hasRemainingVisibleSegments(segments: string[], startIndex: number): boolean {\n for (let i = startIndex; i < segments.length; i++) {\n if (!isInvisibleSegment(segments[i])) return true;\n }\n return false;\n}\n\n// Trie cache — keyed by route array identity (same array = same trie)\nconst appTrieCache = new WeakMap<AppRoute[], TrieNode<AppRoute>>();\n\nfunction getOrBuildAppTrie(routes: AppRoute[]): TrieNode<AppRoute> {\n let trie = appTrieCache.get(routes);\n if (!trie) {\n trie = buildRouteTrie(routes);\n appTrieCache.set(routes, trie);\n }\n return trie;\n}\n\nfunction joinRoutePattern(basePattern: string, subPath: string): string {\n if (!subPath) return basePattern;\n return basePattern === \"/\" ? `/${subPath}` : `${basePattern}/${subPath}`;\n}\n\n/**\n * Match a URL against App Router routes.\n */\nexport function matchAppRoute(\n url: string,\n routes: AppRoute[],\n): { route: AppRoute; params: Record<string, string | string[]> } | null {\n const pathname = url.split(\"?\")[0];\n let normalizedUrl = pathname === \"/\" ? \"/\" : pathname.replace(/\\/$/, \"\");\n normalizedUrl = normalizePathnameForRouteMatch(normalizedUrl);\n\n // Split URL once, look up via trie\n const urlParts = normalizedUrl.split(\"/\").filter(Boolean);\n const trie = getOrBuildAppTrie(routes);\n return trieMatch(trie, urlParts);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2HA,IAAI,eAAkC;AACtC,IAAI,eAA8B;AAClC,IAAI,0BAAyC;AAE7C,SAAgB,0BAAgC;AAC9C,gBAAe;AACf,gBAAe;AACf,2BAA0B;;;;;AAM5B,eAAsB,UACpB,QACA,gBACA,SACqB;AACrB,aAAY,uBAAuB,eAAe;CAClD,MAAM,oBAAoB,KAAK,UAAU,QAAQ,WAAW;AAC5D,KAAI,gBAAgB,iBAAiB,UAAU,4BAA4B,kBACzE,QAAO;CAMT,MAAM,SAAqB,EAAE;CAE7B,MAAM,cAAc,SAA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CACjE,IAAI,OAAO,aAAa,IAAI,OAAO;AACnC,KAAI,CAAC,MAAM;AACT,SAAO,eAAe,OAAO;AAC7B,eAAa,IAAI,QAAQ,KAAK;;AAEhC,QAAO;;AAGT,SAAS,iBAAiB,aAAqB,SAAyB;AACtE,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,gBAAgB,MAAM,IAAI,YAAY,GAAG,YAAY,GAAG;;;;;AAMjE,SAAgB,cACd,KACA,QACuE;CACvE,MAAM,WAAW,IAAI,MAAM,IAAI,CAAC;CAChC,IAAI,gBAAgB,aAAa,MAAM,MAAM,SAAS,QAAQ,OAAO,GAAG;AACxE,iBAAgB,+BAA+B,cAAc;CAG7D,MAAM,WAAW,cAAc,MAAM,IAAI,CAAC,OAAO,QAAQ;AAEzD,QAAO,UADM,kBAAkB,OAAO,EACf,SAAS"}
1
+ {"version":3,"file":"app-router.js","names":[],"sources":["../../src/routing/app-router.ts"],"sourcesContent":["/**\n * App Router file-system routing.\n *\n * Scans the app/ directory following Next.js App Router conventions:\n * - app/page.tsx -> /\n * - app/about/page.tsx -> /about\n * - app/blog/[slug]/page.tsx -> /blog/:slug\n * - app/[...catchAll]/page.tsx -> /:catchAll+\n * - app/route.ts -> / (API route)\n * - app/(group)/page.tsx -> / (route groups are transparent)\n * - Layouts: app/layout.tsx wraps all children\n * - Loading: app/loading.tsx -> Suspense fallback\n * - Error: app/error.tsx -> ErrorBoundary\n * - Not Found: app/not-found.tsx\n */\nimport path from \"node:path\";\nimport fs from \"node:fs\";\nimport { compareRoutes, decodeRouteSegment, normalizePathnameForRouteMatch } from \"./utils.js\";\nimport {\n createValidFileMatcher,\n scanWithExtensions,\n type ValidFileMatcher,\n} from \"./file-matcher.js\";\nimport { validateRoutePatterns } from \"./route-validation.js\";\nimport { buildRouteTrie, trieMatch, type TrieNode } from \"./route-trie.js\";\n\nexport type InterceptingRoute = {\n /** The interception convention: \".\" | \"..\" | \"../..\" | \"...\" */\n convention: string;\n /** The URL pattern this intercepts (e.g. \"/photos/:id\") */\n targetPattern: string;\n /** Absolute path to the intercepting page component */\n pagePath: string;\n /** Parameter names for dynamic segments */\n params: string[];\n};\n\nexport type ParallelSlot = {\n /** Slot name (e.g. \"team\" from @team) */\n name: string;\n /** Absolute path to the @slot directory that owns this slot. Internal routing metadata. */\n ownerDir: string;\n /** Absolute path to the slot's page component */\n pagePath: string | null;\n /** Absolute path to the slot's default.tsx fallback */\n defaultPath: string | null;\n /** Absolute path to the slot's layout component (wraps slot content) */\n layoutPath: string | null;\n /** Absolute path to the slot's loading component */\n loadingPath: string | null;\n /** Absolute path to the slot's error component */\n errorPath: string | null;\n /** Intercepting routes within this slot */\n interceptingRoutes: InterceptingRoute[];\n /**\n * The layout index (0-based, in route.layouts[]) that this slot belongs to.\n * Slots are passed as props to the layout at their directory level, not\n * necessarily the innermost layout. -1 means \"innermost\" (legacy default).\n */\n layoutIndex: number;\n /**\n * Filesystem segments from the slot's root directory to its active page.\n * Used at render time to compute segments for useSelectedLayoutSegment(slotName).\n * For a page at the slot root (@team/page.tsx), this is [].\n * For a sub-page (@team/members/page.tsx), this is [\"members\"].\n * null when the slot has no active page (showing default.tsx fallback).\n */\n routeSegments: string[] | null;\n};\n\nexport type AppRoute = {\n /** URL pattern, e.g. \"/\" or \"/about\" or \"/blog/:slug\" */\n pattern: string;\n /** Absolute file path to the page component */\n pagePath: string | null;\n /** Absolute file path to the route handler (route.ts) */\n routePath: string | null;\n /** Ordered list of layout files from root to leaf */\n layouts: string[];\n /** Template files aligned with layouts array (null where no template exists at that level) */\n templates: (string | null)[];\n /** Parallel route slots (from @slot directories at the route's directory level) */\n parallelSlots: ParallelSlot[];\n /** Loading component path */\n loadingPath: string | null;\n /** Error component path (leaf directory only) */\n errorPath: string | null;\n /**\n * Per-layout error boundary paths, aligned with the layouts array.\n * Each entry is the error.tsx at the same directory level as the\n * corresponding layout (or null if that level has no error.tsx).\n * Used to interleave ErrorBoundary components with layouts so that\n * ancestor error boundaries catch errors from descendant segments.\n */\n layoutErrorPaths: (string | null)[];\n /** Not-found component path (nearest, walking up from page dir) */\n notFoundPath: string | null;\n /**\n * Not-found component paths per layout level (aligned with layouts array).\n * Each entry is the not-found.tsx at that layout's directory, or null.\n * Used to create per-layout NotFoundBoundary so that notFound() thrown from\n * a layout is caught by the parent layout's boundary (matching Next.js behavior).\n */\n notFoundPaths: (string | null)[];\n /** Forbidden component path (403) */\n forbiddenPath: string | null;\n /** Unauthorized component path (401) */\n unauthorizedPath: string | null;\n /**\n * Filesystem segments from app/ root to the route's directory.\n * Includes route groups and dynamic segments (as template strings like \"[id]\").\n * Used at render time to compute the child segments for useSelectedLayoutSegments().\n */\n routeSegments: string[];\n /**\n * Tree position (directory depth from app/ root) for each layout.\n * Used to slice routeSegments and determine which segments are below each layout.\n * For example, root layout = 0, a layout at app/blog/ = 1, app/blog/(group)/ = 2.\n * Unlike the old layoutSegmentDepths, this counts ALL directory levels including\n * route groups and parallel slots.\n */\n layoutTreePositions: number[];\n /** Whether this is a dynamic route */\n isDynamic: boolean;\n /** Parameter names for dynamic segments */\n params: string[];\n /** Pre-split pattern segments (computed once at scan time, reused per request) */\n patternParts: string[];\n};\n\n// Cache for app routes\nlet cachedRoutes: AppRoute[] | null = null;\nlet cachedAppDir: string | null = null;\nlet cachedPageExtensionsKey: string | null = null;\n\nexport function invalidateAppRouteCache(): void {\n cachedRoutes = null;\n cachedAppDir = null;\n cachedPageExtensionsKey = null;\n}\n\n/**\n * Scan the app/ directory and return a list of routes.\n */\nexport async function appRouter(\n appDir: string,\n pageExtensions?: readonly string[],\n matcher?: ValidFileMatcher,\n): Promise<AppRoute[]> {\n matcher ??= createValidFileMatcher(pageExtensions);\n const pageExtensionsKey = JSON.stringify(matcher.extensions);\n if (cachedRoutes && cachedAppDir === appDir && cachedPageExtensionsKey === pageExtensionsKey) {\n return cachedRoutes;\n }\n\n // Find all page.tsx and route.ts files, excluding @slot directories\n // (slot pages are not standalone routes — they're rendered as props of their parent layout)\n // and _private folders (Next.js convention for colocated non-route files).\n const routes: AppRoute[] = [];\n\n const excludeDir = (name: string) => name.startsWith(\"@\") || name.startsWith(\"_\");\n\n // Process page files in a single pass\n // Use function form of exclude for Node < 22.14 compatibility (string arrays require >= 22.14)\n for await (const file of scanWithExtensions(\"**/page\", appDir, matcher.extensions, excludeDir)) {\n const route = fileToAppRoute(file, appDir, \"page\", matcher);\n if (route) routes.push(route);\n }\n\n // Process route handler files (API routes) in a single pass\n for await (const file of scanWithExtensions(\"**/route\", appDir, matcher.extensions, excludeDir)) {\n const route = fileToAppRoute(file, appDir, \"route\", matcher);\n if (route) routes.push(route);\n }\n\n // Discover sub-routes created by nested pages within parallel slots.\n // In Next.js, pages nested inside @slot directories create additional URL routes.\n // For example, @audience/demographics/page.tsx at app/parallel-routes/ creates\n // a route at /parallel-routes/demographics.\n const slotSubRoutes = discoverSlotSubRoutes(routes, appDir, matcher);\n routes.push(...slotSubRoutes);\n\n validateRoutePatterns(routes.map((route) => route.pattern));\n // Deduplicate intercept target patterns: child routes inherit parent slots\n // (including their intercepting routes), so the same target pattern can appear\n // on both the parent and child route. Collect unique patterns only.\n const interceptTargetPatterns = [\n ...new Set(\n routes.flatMap((route) =>\n route.parallelSlots.flatMap((slot) =>\n slot.interceptingRoutes.map((intercept) => intercept.targetPattern),\n ),\n ),\n ),\n ];\n validateRoutePatterns(interceptTargetPatterns);\n\n // Sort: static routes first, then dynamic, then catch-all\n routes.sort(compareRoutes);\n\n cachedRoutes = routes;\n cachedAppDir = appDir;\n cachedPageExtensionsKey = pageExtensionsKey;\n return routes;\n}\n\n/**\n * Discover sub-routes created by nested pages within parallel slots.\n *\n * In Next.js, pages nested inside @slot directories create additional URL routes.\n * For example, given:\n * app/parallel-routes/@audience/demographics/page.tsx\n * This creates a route at /parallel-routes/demographics where:\n * - children slot → parent's default.tsx\n * - @audience slot → @audience/demographics/page.tsx (matched)\n * - other slots → their default.tsx (fallback)\n */\nfunction discoverSlotSubRoutes(\n routes: AppRoute[],\n _appDir: string,\n matcher: ValidFileMatcher,\n): AppRoute[] {\n const syntheticRoutes: AppRoute[] = [];\n\n // O(1) lookup for existing routes by pattern — avoids O(n) routes.find() per sub-path per parent.\n // Updated as new synthetic routes are pushed so that later parents can see earlier synthetic entries.\n const routesByPattern = new Map<string, AppRoute>(routes.map((r) => [r.pattern, r]));\n\n const slotKey = (slotName: string, ownerDir: string): string => `${slotName}\\u0000${ownerDir}`;\n\n const applySlotSubPages = (\n route: AppRoute,\n slotPages: Map<string, string>,\n rawSegments: string[],\n ): void => {\n route.parallelSlots = route.parallelSlots.map((slot) => {\n const subPage = slotPages.get(slotKey(slot.name, slot.ownerDir));\n if (subPage !== undefined) {\n return { ...slot, pagePath: subPage, routeSegments: rawSegments };\n }\n return slot;\n });\n };\n\n for (const parentRoute of routes) {\n if (parentRoute.parallelSlots.length === 0) continue;\n if (!parentRoute.pagePath) continue;\n\n const parentPageDir = path.dirname(parentRoute.pagePath);\n\n // Collect sub-paths from all slots.\n // Map: normalized visible sub-path -> slot pages, raw filesystem segments (for routeSegments),\n // and the pre-computed convertedSubRoute (to avoid a redundant re-conversion in the merge loop).\n const subPathMap = new Map<\n string,\n {\n // Raw filesystem segments (with route groups, @slots, etc.) used for routeSegments so\n // that useSelectedLayoutSegments() sees the correct segment list at runtime.\n rawSegments: string[];\n // Pre-computed URL parts, params, isDynamic from convertSegmentsToRouteParts.\n converted: {\n urlSegments: string[];\n params: string[];\n isDynamic: boolean;\n };\n slotPages: Map<string, string>;\n }\n >();\n\n for (const slot of parentRoute.parallelSlots) {\n const slotDir = path.join(parentPageDir, `@${slot.name}`);\n if (!fs.existsSync(slotDir)) continue;\n\n const subPages = findSlotSubPages(slotDir, matcher);\n for (const { relativePath, pagePath } of subPages) {\n const subSegments = relativePath.split(path.sep);\n const convertedSubRoute = convertSegmentsToRouteParts(subSegments);\n if (!convertedSubRoute) continue;\n\n const { urlSegments } = convertedSubRoute;\n const normalizedSubPath = urlSegments.join(\"/\");\n let subPathEntry = subPathMap.get(normalizedSubPath);\n\n if (!subPathEntry) {\n subPathEntry = {\n rawSegments: subSegments,\n converted: convertedSubRoute,\n slotPages: new Map(),\n };\n subPathMap.set(normalizedSubPath, subPathEntry);\n }\n\n const slotId = slotKey(slot.name, slot.ownerDir);\n const existingSlotPage = subPathEntry.slotPages.get(slotId);\n if (existingSlotPage) {\n const pattern = joinRoutePattern(parentRoute.pattern, normalizedSubPath);\n throw new Error(\n `You cannot have two routes that resolve to the same path (\"${pattern}\").`,\n );\n }\n\n subPathEntry.slotPages.set(slotId, pagePath);\n }\n }\n\n if (subPathMap.size === 0) continue;\n\n // Find the default.tsx for the children slot at the parent directory\n const childrenDefault = findFile(parentPageDir, \"default\", matcher);\n if (!childrenDefault) continue;\n\n for (const { rawSegments, converted: convertedSubRoute, slotPages } of subPathMap.values()) {\n const {\n urlSegments: urlParts,\n params: subParams,\n isDynamic: subIsDynamic,\n } = convertedSubRoute;\n\n const subUrlPath = urlParts.join(\"/\");\n const pattern = joinRoutePattern(parentRoute.pattern, subUrlPath);\n\n const existingRoute = routesByPattern.get(pattern);\n if (existingRoute) {\n if (existingRoute.routePath && !existingRoute.pagePath) {\n throw new Error(\n `You cannot have two routes that resolve to the same path (\"${pattern}\").`,\n );\n }\n applySlotSubPages(existingRoute, slotPages, rawSegments);\n continue;\n }\n\n // Build parallel slots for this sub-route: matching slots get the sub-page,\n // non-matching slots get null pagePath (rendering falls back to defaultPath)\n const subSlots: ParallelSlot[] = parentRoute.parallelSlots.map((slot) => {\n const subPage = slotPages.get(slotKey(slot.name, slot.ownerDir));\n return {\n ...slot,\n pagePath: subPage || null,\n routeSegments: subPage ? rawSegments : null,\n };\n });\n\n const newRoute: AppRoute = {\n pattern,\n pagePath: childrenDefault, // children slot uses parent's default.tsx as page\n routePath: null,\n layouts: parentRoute.layouts,\n templates: parentRoute.templates,\n parallelSlots: subSlots,\n loadingPath: parentRoute.loadingPath,\n errorPath: parentRoute.errorPath,\n layoutErrorPaths: parentRoute.layoutErrorPaths,\n notFoundPath: parentRoute.notFoundPath,\n notFoundPaths: parentRoute.notFoundPaths,\n forbiddenPath: parentRoute.forbiddenPath,\n unauthorizedPath: parentRoute.unauthorizedPath,\n routeSegments: [...parentRoute.routeSegments, ...rawSegments],\n layoutTreePositions: parentRoute.layoutTreePositions,\n isDynamic: parentRoute.isDynamic || subIsDynamic,\n params: [...parentRoute.params, ...subParams],\n patternParts: [...parentRoute.patternParts, ...urlParts],\n };\n syntheticRoutes.push(newRoute);\n routesByPattern.set(pattern, newRoute);\n }\n }\n\n return syntheticRoutes;\n}\n\n/**\n * Find all page files in subdirectories of a parallel slot directory.\n * Returns relative paths (from the slot dir) and absolute page paths.\n * Skips the root page.tsx (already handled as the slot's main page)\n * and intercepting route directories.\n */\nfunction findSlotSubPages(\n slotDir: string,\n matcher: ValidFileMatcher,\n): Array<{ relativePath: string; pagePath: string }> {\n const results: Array<{ relativePath: string; pagePath: string }> = [];\n\n function scan(dir: string): void {\n if (!fs.existsSync(dir)) return;\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n // Skip intercepting route directories\n if (matchInterceptConvention(entry.name)) continue;\n // Skip private folders (prefixed with _)\n if (entry.name.startsWith(\"_\")) continue;\n\n const subDir = path.join(dir, entry.name);\n const page = findFile(subDir, \"page\", matcher);\n if (page) {\n const relativePath = path.relative(slotDir, subDir);\n results.push({ relativePath, pagePath: page });\n }\n // Continue scanning deeper for nested sub-pages\n scan(subDir);\n }\n }\n\n scan(slotDir);\n return results;\n}\n\n/**\n * Convert a file path relative to app/ into an AppRoute.\n */\nfunction fileToAppRoute(\n file: string,\n appDir: string,\n type: \"page\" | \"route\",\n matcher: ValidFileMatcher,\n): AppRoute | null {\n // Remove the filename (page.tsx or route.ts)\n const dir = path.dirname(file);\n const segments = dir === \".\" ? [] : dir.split(path.sep);\n\n const params: string[] = [];\n let isDynamic = false;\n\n const convertedRoute = convertSegmentsToRouteParts(segments);\n if (!convertedRoute) return null;\n\n const { urlSegments, params: routeParams, isDynamic: routeIsDynamic } = convertedRoute;\n params.push(...routeParams);\n isDynamic = routeIsDynamic;\n\n const pattern = \"/\" + urlSegments.join(\"/\");\n\n // Discover layouts and layout-aligned templates from root to leaf\n const layouts = discoverLayouts(segments, appDir, matcher);\n const templates = discoverLayoutAlignedTemplates(segments, appDir, matcher);\n\n // Compute the tree position (directory depth) for each layout.\n const layoutTreePositions = computeLayoutTreePositions(appDir, layouts);\n\n // Discover per-layout error boundaries (aligned with layouts array).\n // In Next.js, each segment independently wraps its children with an ErrorBoundary.\n // This array enables interleaving error boundaries with layouts in the rendering.\n const layoutErrorPaths = discoverLayoutAlignedErrors(segments, appDir, matcher);\n\n // Discover loading, error in the route's directory\n const routeDir = dir === \".\" ? appDir : path.join(appDir, dir);\n const loadingPath = findFile(routeDir, \"loading\", matcher);\n const errorPath = findFile(routeDir, \"error\", matcher);\n\n // Discover not-found/forbidden/unauthorized: walk from route directory up to root (nearest wins).\n const notFoundPath = discoverBoundaryFile(segments, appDir, \"not-found\", matcher);\n const forbiddenPath = discoverBoundaryFile(segments, appDir, \"forbidden\", matcher);\n const unauthorizedPath = discoverBoundaryFile(segments, appDir, \"unauthorized\", matcher);\n\n // Discover per-layout not-found files (one per layout directory).\n // These are used for per-layout NotFoundBoundary to match Next.js behavior where\n // notFound() thrown from a layout is caught by the parent layout's boundary.\n const notFoundPaths = discoverBoundaryFilePerLayout(layouts, \"not-found\", matcher);\n\n // Discover parallel slots (@team, @analytics, etc.).\n // Slots at the route's own directory use page.tsx; slots at ancestor directories\n // (inherited from parent layouts) use default.tsx as fallback.\n const parallelSlots = discoverInheritedParallelSlots(segments, appDir, routeDir, matcher);\n\n return {\n pattern: pattern === \"/\" ? \"/\" : pattern,\n pagePath: type === \"page\" ? path.join(appDir, file) : null,\n routePath: type === \"route\" ? path.join(appDir, file) : null,\n layouts,\n templates,\n parallelSlots,\n loadingPath,\n errorPath,\n layoutErrorPaths,\n notFoundPath,\n notFoundPaths,\n forbiddenPath,\n unauthorizedPath,\n routeSegments: segments,\n layoutTreePositions,\n isDynamic,\n params,\n patternParts: urlSegments,\n };\n}\n\n/**\n * Compute the tree position (directory depth from app root) for each layout.\n * Root layout = 0, a layout at app/blog/ = 1, app/blog/(group)/ = 2.\n * Counts ALL directory levels including route groups and parallel slots.\n */\nfunction computeLayoutTreePositions(appDir: string, layouts: string[]): number[] {\n return layouts.map((layoutPath) => {\n const layoutDir = path.dirname(layoutPath);\n if (layoutDir === appDir) return 0;\n const relative = path.relative(appDir, layoutDir);\n return relative.split(path.sep).length;\n });\n}\n\n/**\n * Discover all layout files from root to the given directory.\n * Each level of the directory tree may have a layout.tsx.\n */\nfunction discoverLayouts(segments: string[], appDir: string, matcher: ValidFileMatcher): string[] {\n const layouts: string[] = [];\n\n // Check root layout\n const rootLayout = findFile(appDir, \"layout\", matcher);\n if (rootLayout) layouts.push(rootLayout);\n\n // Check each directory level\n let currentDir = appDir;\n for (const segment of segments) {\n currentDir = path.join(currentDir, segment);\n const layout = findFile(currentDir, \"layout\", matcher);\n if (layout) layouts.push(layout);\n }\n\n return layouts;\n}\n\n/**\n * Discover template files aligned with the layouts array.\n * Walks the same directory levels as discoverLayouts and, for each level\n * that contributes a layout entry, checks whether template.tsx also exists.\n * Returns an array of the same length as discoverLayouts() would return,\n * with the template path (or null) at each corresponding layout level.\n *\n * This enables interleaving templates with their corresponding layouts,\n * matching Next.js behavior where each segment's hierarchy is\n * Layout > Template > ErrorBoundary > children.\n */\nfunction discoverLayoutAlignedTemplates(\n segments: string[],\n appDir: string,\n matcher: ValidFileMatcher,\n): (string | null)[] {\n const templates: (string | null)[] = [];\n\n // Root level (only if root has a layout — matching discoverLayouts logic)\n const rootLayout = findFile(appDir, \"layout\", matcher);\n if (rootLayout) {\n templates.push(findFile(appDir, \"template\", matcher));\n }\n\n // Check each directory level\n let currentDir = appDir;\n for (const segment of segments) {\n currentDir = path.join(currentDir, segment);\n const layout = findFile(currentDir, \"layout\", matcher);\n if (layout) {\n templates.push(findFile(currentDir, \"template\", matcher));\n }\n }\n\n return templates;\n}\n\n/**\n * Discover error.tsx files aligned with the layouts array.\n * Walks the same directory levels as discoverLayouts and, for each level\n * that contributes a layout entry, checks whether error.tsx also exists.\n * Returns an array of the same length as discoverLayouts() would return,\n * with the error path (or null) at each corresponding layout level.\n *\n * This enables interleaving ErrorBoundary components with layouts in the\n * rendering tree, matching Next.js behavior where each segment independently\n * wraps its children with an error boundary.\n */\nfunction discoverLayoutAlignedErrors(\n segments: string[],\n appDir: string,\n matcher: ValidFileMatcher,\n): (string | null)[] {\n const errors: (string | null)[] = [];\n\n // Root level (only if root has a layout — matching discoverLayouts logic)\n const rootLayout = findFile(appDir, \"layout\", matcher);\n if (rootLayout) {\n errors.push(findFile(appDir, \"error\", matcher));\n }\n\n // Check each directory level\n let currentDir = appDir;\n for (const segment of segments) {\n currentDir = path.join(currentDir, segment);\n const layout = findFile(currentDir, \"layout\", matcher);\n if (layout) {\n errors.push(findFile(currentDir, \"error\", matcher));\n }\n }\n\n return errors;\n}\n\n/**\n * Discover the nearest boundary file (not-found, forbidden, unauthorized)\n * by walking from the route's directory up to the app root.\n * Returns the first (closest) file found, or null.\n */\nfunction discoverBoundaryFile(\n segments: string[],\n appDir: string,\n fileName: string,\n matcher: ValidFileMatcher,\n): string | null {\n // Build all directory paths from leaf to root\n const dirs: string[] = [];\n let dir = appDir;\n dirs.push(dir);\n for (const segment of segments) {\n dir = path.join(dir, segment);\n dirs.push(dir);\n }\n\n // Walk from leaf (last) to root (first)\n for (let i = dirs.length - 1; i >= 0; i--) {\n const f = findFile(dirs[i], fileName, matcher);\n if (f) return f;\n }\n return null;\n}\n\n/**\n * Discover boundary files (not-found, forbidden, unauthorized) at each layout directory.\n * Returns an array aligned with the layouts array, where each entry is the boundary\n * file at that layout's directory, or null if none exists there.\n *\n * This is used for per-layout error boundaries. In Next.js, each layout level\n * has its own boundary that wraps the layout's children. When notFound() is thrown\n * from a layout, it propagates up to the parent layout's boundary.\n */\nfunction discoverBoundaryFilePerLayout(\n layouts: string[],\n fileName: string,\n matcher: ValidFileMatcher,\n): (string | null)[] {\n return layouts.map((layoutPath) => {\n const layoutDir = path.dirname(layoutPath);\n return findFile(layoutDir, fileName, matcher);\n });\n}\n\n/**\n * Discover parallel slots inherited from ancestor directories.\n *\n * In Next.js, parallel slots belong to the layout that defines them. When a\n * child route is rendered, its parent layout's slots must still be present.\n * If the child doesn't have matching content in a slot, the slot's default.tsx\n * is rendered instead.\n *\n * Walk from appDir through each segment to the route's directory. At each level\n * that has @slot dirs, collect them. Slots at the route's own directory level\n * use page.tsx; slots at ancestor levels use default.tsx only.\n */\nfunction discoverInheritedParallelSlots(\n segments: string[],\n appDir: string,\n routeDir: string,\n matcher: ValidFileMatcher,\n): ParallelSlot[] {\n const slotMap = new Map<string, ParallelSlot>();\n\n // Walk from appDir through each segment, tracking layout indices.\n // layoutIndex tracks which position in the route's layouts[] array corresponds\n // to a given directory. Only directories with a layout.tsx file increment.\n let currentDir = appDir;\n const dirsToCheck: { dir: string; layoutIdx: number }[] = [];\n let layoutIdx = findFile(appDir, \"layout\", matcher) ? 0 : -1;\n dirsToCheck.push({ dir: appDir, layoutIdx: Math.max(layoutIdx, 0) });\n\n for (const segment of segments) {\n currentDir = path.join(currentDir, segment);\n if (findFile(currentDir, \"layout\", matcher)) {\n layoutIdx++;\n }\n dirsToCheck.push({ dir: currentDir, layoutIdx: Math.max(layoutIdx, 0) });\n }\n\n for (const { dir, layoutIdx: lvlLayoutIdx } of dirsToCheck) {\n const isOwnDir = dir === routeDir;\n const slotsAtLevel = discoverParallelSlots(dir, appDir, matcher);\n\n for (const slot of slotsAtLevel) {\n if (isOwnDir) {\n // At the route's own directory: use page.tsx (normal behavior)\n slot.layoutIndex = lvlLayoutIdx;\n slotMap.set(slot.name, slot);\n } else {\n // At an ancestor directory: use default.tsx as the page, not page.tsx\n // (the slot's page.tsx is for the parent route, not this child route)\n const inheritedSlot: ParallelSlot = {\n ...slot,\n pagePath: null, // Don't use ancestor's page.tsx\n layoutIndex: lvlLayoutIdx,\n routeSegments: null, // Inherited slot shows default.tsx, not an active page\n // defaultPath, loadingPath, errorPath, interceptingRoutes remain\n };\n // Iteration goes root-to-leaf, so later (closer) ancestors overwrite\n // earlier (farther) ones — the closest ancestor's slot wins.\n slotMap.set(slot.name, inheritedSlot);\n }\n }\n }\n\n return Array.from(slotMap.values());\n}\n\n/**\n * Discover parallel route slots (@team, @analytics, etc.) in a directory.\n * Returns a ParallelSlot for each @-prefixed subdirectory that has a page or default component.\n */\nfunction discoverParallelSlots(\n dir: string,\n appDir: string,\n matcher: ValidFileMatcher,\n): ParallelSlot[] {\n if (!fs.existsSync(dir)) return [];\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n const slots: ParallelSlot[] = [];\n\n for (const entry of entries) {\n if (!entry.isDirectory() || !entry.name.startsWith(\"@\")) continue;\n\n const slotName = entry.name.slice(1); // \"@team\" -> \"team\"\n const slotDir = path.join(dir, entry.name);\n\n const pagePath = findFile(slotDir, \"page\", matcher);\n const defaultPath = findFile(slotDir, \"default\", matcher);\n const interceptingRoutes = discoverInterceptingRoutes(slotDir, dir, appDir, matcher);\n\n // Only include slots that have at least a page, default, or intercepting route\n if (!pagePath && !defaultPath && interceptingRoutes.length === 0) continue;\n\n slots.push({\n name: slotName,\n ownerDir: slotDir,\n pagePath,\n defaultPath,\n layoutPath: findFile(slotDir, \"layout\", matcher),\n loadingPath: findFile(slotDir, \"loading\", matcher),\n errorPath: findFile(slotDir, \"error\", matcher),\n interceptingRoutes,\n layoutIndex: -1, // Will be set by discoverInheritedParallelSlots\n routeSegments: pagePath ? [] : null, // Root page = [], no page = null (default fallback)\n });\n }\n\n return slots;\n}\n\n/**\n * The interception convention prefix patterns.\n * (.) — same level, (..) — one level up, (..)(..)\" — two levels up, (...) — root\n */\nconst INTERCEPT_PATTERNS = [\n { prefix: \"(...)\", convention: \"...\" },\n { prefix: \"(..)(..)\", convention: \"../..\" },\n { prefix: \"(..)\", convention: \"..\" },\n { prefix: \"(.)\", convention: \".\" },\n] as const;\n\n/**\n * Discover intercepting routes inside a parallel slot directory.\n *\n * Intercepting routes use conventions like (.)photo, (..)feed, (...), etc.\n * They intercept navigation to another route and render within the slot instead.\n *\n * @param slotDir - The parallel slot directory (e.g. app/feed/@modal)\n * @param routeDir - The directory of the route that owns this slot (e.g. app/feed)\n * @param appDir - The root app directory\n */\nfunction discoverInterceptingRoutes(\n slotDir: string,\n routeDir: string,\n appDir: string,\n matcher: ValidFileMatcher,\n): InterceptingRoute[] {\n if (!fs.existsSync(slotDir)) return [];\n\n const results: InterceptingRoute[] = [];\n\n // Recursively scan for page files inside intercepting directories\n scanForInterceptingPages(slotDir, routeDir, appDir, results, matcher);\n\n return results;\n}\n\n/**\n * Recursively scan a directory tree for page.tsx files that are inside\n * intercepting route directories.\n */\nfunction scanForInterceptingPages(\n currentDir: string,\n routeDir: string,\n appDir: string,\n results: InterceptingRoute[],\n matcher: ValidFileMatcher,\n): void {\n if (!fs.existsSync(currentDir)) return;\n\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\n\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n // Skip private folders (prefixed with _)\n if (entry.name.startsWith(\"_\")) continue;\n\n // Check if this directory name starts with an interception convention\n const interceptMatch = matchInterceptConvention(entry.name);\n\n if (interceptMatch) {\n // This directory is the start of an intercepting route\n // e.g. \"(.)photos\" means intercept same-level \"photos\" route\n const restOfName = entry.name.slice(interceptMatch.prefix.length);\n const interceptDir = path.join(currentDir, entry.name);\n\n // Find page files within this intercepting directory tree\n collectInterceptingPages(\n interceptDir,\n interceptDir,\n interceptMatch.convention,\n restOfName,\n routeDir,\n appDir,\n results,\n matcher,\n );\n } else {\n // Regular subdirectory — keep scanning for intercepting dirs\n scanForInterceptingPages(\n path.join(currentDir, entry.name),\n routeDir,\n appDir,\n results,\n matcher,\n );\n }\n }\n}\n\n/**\n * Match a directory name against interception convention prefixes.\n */\nfunction matchInterceptConvention(name: string): { prefix: string; convention: string } | null {\n for (const pattern of INTERCEPT_PATTERNS) {\n if (name.startsWith(pattern.prefix)) {\n return pattern;\n }\n }\n return null;\n}\n\n/**\n * Collect page.tsx files inside an intercepting route directory tree\n * and compute their target URL patterns.\n */\nfunction collectInterceptingPages(\n currentDir: string,\n interceptRoot: string,\n convention: string,\n interceptSegment: string,\n routeDir: string,\n appDir: string,\n results: InterceptingRoute[],\n matcher: ValidFileMatcher,\n): void {\n // Check for page.tsx in current directory\n const page = findFile(currentDir, \"page\", matcher);\n if (page) {\n const targetPattern = computeInterceptTarget(\n convention,\n interceptSegment,\n currentDir,\n interceptRoot,\n routeDir,\n appDir,\n );\n if (targetPattern) {\n results.push({\n convention,\n targetPattern: targetPattern.pattern,\n pagePath: page,\n params: targetPattern.params,\n });\n }\n }\n\n // Recurse into subdirectories for nested intercepting routes\n if (!fs.existsSync(currentDir)) return;\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n // Skip private folders (prefixed with _)\n if (entry.name.startsWith(\"_\")) continue;\n collectInterceptingPages(\n path.join(currentDir, entry.name),\n interceptRoot,\n convention,\n interceptSegment,\n routeDir,\n appDir,\n results,\n matcher,\n );\n }\n}\n\n/**\n * Check whether a path segment is invisible in the URL (route groups, parallel slots, \".\").\n *\n * Used by computeInterceptTarget, convertSegmentsToRouteParts, and\n * hasRemainingVisibleSegments — keep this the single source of truth.\n */\nfunction isInvisibleSegment(segment: string): boolean {\n if (segment === \".\") return true;\n if (segment.startsWith(\"(\") && segment.endsWith(\")\")) return true;\n if (segment.startsWith(\"@\")) return true;\n return false;\n}\n\n/**\n * Compute the target URL pattern for an intercepting route.\n *\n * Interception conventions (..), (..)(..)\" climb by *visible route segments*\n * (not filesystem directories). Route groups like (marketing) and parallel\n * slots like @modal are invisible and must be skipped when counting levels.\n *\n * - (.) same level: resolve relative to routeDir\n * - (..) one level up: climb 1 visible segment\n * - (..)(..) two levels up: climb 2 visible segments\n * - (...) root: resolve from appDir\n */\nfunction computeInterceptTarget(\n convention: string,\n interceptSegment: string,\n currentDir: string,\n interceptRoot: string,\n routeDir: string,\n appDir: string,\n): { pattern: string; params: string[] } | null {\n // Determine the base segments for target resolution.\n // We work on route segments (not filesystem paths) so that route groups\n // and parallel slots are properly skipped when climbing.\n const routeSegments = path.relative(appDir, routeDir).split(path.sep).filter(Boolean);\n\n let baseParts: string[];\n switch (convention) {\n case \".\":\n baseParts = routeSegments;\n break;\n case \"..\":\n case \"../..\": {\n const levelsToClimb = convention === \"..\" ? 1 : 2;\n let climbed = 0;\n let cutIndex = routeSegments.length;\n while (cutIndex > 0 && climbed < levelsToClimb) {\n cutIndex--;\n if (!isInvisibleSegment(routeSegments[cutIndex])) {\n climbed++;\n }\n }\n baseParts = routeSegments.slice(0, cutIndex);\n break;\n }\n case \"...\":\n baseParts = [];\n break;\n default:\n return null;\n }\n\n // Add the intercept segment and any nested path segments\n const nestedParts = path.relative(interceptRoot, currentDir).split(path.sep).filter(Boolean);\n const allSegments = [...baseParts, interceptSegment, ...nestedParts];\n\n const convertedTarget = convertSegmentsToRouteParts(allSegments);\n if (!convertedTarget) return null;\n\n const { urlSegments, params } = convertedTarget;\n\n const pattern = \"/\" + urlSegments.join(\"/\");\n return { pattern: pattern === \"/\" ? \"/\" : pattern, params };\n}\n\n/**\n * Find a file by name (without extension) in a directory.\n * Checks configured pageExtensions.\n */\nfunction findFile(dir: string, name: string, matcher: ValidFileMatcher): string | null {\n for (const ext of matcher.dottedExtensions) {\n const filePath = path.join(dir, name + ext);\n if (fs.existsSync(filePath)) return filePath;\n }\n return null;\n}\n\n/**\n * Convert filesystem path segments to URL route parts, skipping invisible segments\n * (route groups, @slots, \".\") and converting dynamic segment syntax to Express-style\n * patterns (e.g. \"[id]\" → \":id\", \"[...slug]\" → \":slug+\").\n */\nfunction convertSegmentsToRouteParts(\n segments: string[],\n): { urlSegments: string[]; params: string[]; isDynamic: boolean } | null {\n const urlSegments: string[] = [];\n const params: string[] = [];\n let isDynamic = false;\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i];\n\n if (isInvisibleSegment(segment)) continue;\n\n // Catch-all segments are only valid in terminal URL position.\n const catchAllMatch = segment.match(/^\\[\\.\\.\\.([\\w-]+)\\]$/);\n if (catchAllMatch) {\n if (hasRemainingVisibleSegments(segments, i + 1)) return null;\n isDynamic = true;\n params.push(catchAllMatch[1]);\n urlSegments.push(`:${catchAllMatch[1]}+`);\n continue;\n }\n\n const optionalCatchAllMatch = segment.match(/^\\[\\[\\.\\.\\.([\\w-]+)\\]\\]$/);\n if (optionalCatchAllMatch) {\n if (hasRemainingVisibleSegments(segments, i + 1)) return null;\n isDynamic = true;\n params.push(optionalCatchAllMatch[1]);\n urlSegments.push(`:${optionalCatchAllMatch[1]}*`);\n continue;\n }\n\n const dynamicMatch = segment.match(/^\\[([\\w-]+)\\]$/);\n if (dynamicMatch) {\n isDynamic = true;\n params.push(dynamicMatch[1]);\n urlSegments.push(`:${dynamicMatch[1]}`);\n continue;\n }\n\n urlSegments.push(decodeRouteSegment(segment));\n }\n\n return { urlSegments, params, isDynamic };\n}\n\nfunction hasRemainingVisibleSegments(segments: string[], startIndex: number): boolean {\n for (let i = startIndex; i < segments.length; i++) {\n if (!isInvisibleSegment(segments[i])) return true;\n }\n return false;\n}\n\n// Trie cache — keyed by route array identity (same array = same trie)\nconst appTrieCache = new WeakMap<AppRoute[], TrieNode<AppRoute>>();\n\nfunction getOrBuildAppTrie(routes: AppRoute[]): TrieNode<AppRoute> {\n let trie = appTrieCache.get(routes);\n if (!trie) {\n trie = buildRouteTrie(routes);\n appTrieCache.set(routes, trie);\n }\n return trie;\n}\n\nfunction joinRoutePattern(basePattern: string, subPath: string): string {\n if (!subPath) return basePattern;\n return basePattern === \"/\" ? `/${subPath}` : `${basePattern}/${subPath}`;\n}\n\n/**\n * Match a URL against App Router routes.\n */\nexport function matchAppRoute(\n url: string,\n routes: AppRoute[],\n): { route: AppRoute; params: Record<string, string | string[]> } | null {\n const pathname = url.split(\"?\")[0];\n let normalizedUrl = pathname === \"/\" ? \"/\" : pathname.replace(/\\/$/, \"\");\n normalizedUrl = normalizePathnameForRouteMatch(normalizedUrl);\n\n // Split URL once, look up via trie\n const urlParts = normalizedUrl.split(\"/\").filter(Boolean);\n const trie = getOrBuildAppTrie(routes);\n return trieMatch(trie, urlParts);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmIA,IAAI,eAAkC;AACtC,IAAI,eAA8B;AAClC,IAAI,0BAAyC;AAE7C,SAAgB,0BAAgC;AAC9C,gBAAe;AACf,gBAAe;AACf,2BAA0B;;;;;AAM5B,eAAsB,UACpB,QACA,gBACA,SACqB;AACrB,aAAY,uBAAuB,eAAe;CAClD,MAAM,oBAAoB,KAAK,UAAU,QAAQ,WAAW;AAC5D,KAAI,gBAAgB,iBAAiB,UAAU,4BAA4B,kBACzE,QAAO;CAMT,MAAM,SAAqB,EAAE;CAE7B,MAAM,cAAc,SAAiB,KAAK,WAAW,IAAI,IAAI,KAAK,WAAW,IAAI;AAIjF,YAAW,MAAM,QAAQ,mBAAmB,WAAW,QAAQ,QAAQ,YAAY,WAAW,EAAE;EAC9F,MAAM,QAAQ,eAAe,MAAM,QAAQ,QAAQ,QAAQ;AAC3D,MAAI,MAAO,QAAO,KAAK,MAAM;;AAI/B,YAAW,MAAM,QAAQ,mBAAmB,YAAY,QAAQ,QAAQ,YAAY,WAAW,EAAE;EAC/F,MAAM,QAAQ,eAAe,MAAM,QAAQ,SAAS,QAAQ;AAC5D,MAAI,MAAO,QAAO,KAAK,MAAM;;CAO/B,MAAM,gBAAgB,sBAAsB,QAAQ,QAAQ,QAAQ;AACpE,QAAO,KAAK,GAAG,cAAc;AAE7B,uBAAsB,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC;AAa3D,uBATgC,CAC9B,GAAG,IAAI,IACL,OAAO,SAAS,UACd,M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gBAAgB,aAAa,MAAM,MAAM,SAAS,QAAQ,OAAO,GAAG;AACxE,iBAAgB,+BAA+B,cAAc;CAG7D,MAAM,WAAW,cAAc,MAAM,IAAI,CAAC,OAAO,QAAQ;AAEzD,QAAO,UADM,kBAAkB,OAAO,EACf,SAAS"}
@@ -44,8 +44,19 @@ type BuildAppPageHtmlResponseOptions = {
44
44
  };
45
45
  declare function resolveAppPageRscResponsePolicy(options: ResolveAppPageRscResponsePolicyOptions): AppPageResponsePolicy;
46
46
  declare function resolveAppPageHtmlResponsePolicy(options: ResolveAppPageHtmlResponsePolicyOptions): AppPageHtmlResponsePolicy;
47
+ /**
48
+ * Merge middleware response headers into a target Headers object.
49
+ *
50
+ * Set-Cookie and Vary are accumulated (append) since multiple sources can
51
+ * contribute values. All other headers use set() so middleware owns singular
52
+ * response headers like Cache-Control.
53
+ *
54
+ * Used by buildAppPageRscResponse and the generated entry for intercepting
55
+ * route and server action responses that bypass the normal page render path.
56
+ */
57
+ declare function mergeMiddlewareResponseHeaders(target: Headers, middlewareHeaders: Headers | null): void;
47
58
  declare function buildAppPageRscResponse(body: ReadableStream, options: BuildAppPageRscResponseOptions): Response;
48
59
  declare function buildAppPageHtmlResponse(body: ReadableStream, options: BuildAppPageHtmlResponseOptions): Response;
49
60
  //#endregion
50
- export { AppPageHtmlResponsePolicy, AppPageMiddlewareContext, AppPageResponsePolicy, AppPageResponseTiming, BuildAppPageHtmlResponseOptions, BuildAppPageRscResponseOptions, ResolveAppPageHtmlResponsePolicyOptions, ResolveAppPageRscResponsePolicyOptions, buildAppPageHtmlResponse, buildAppPageRscResponse, resolveAppPageHtmlResponsePolicy, resolveAppPageRscResponsePolicy };
61
+ export { AppPageHtmlResponsePolicy, AppPageMiddlewareContext, AppPageResponsePolicy, AppPageResponseTiming, BuildAppPageHtmlResponseOptions, BuildAppPageRscResponseOptions, ResolveAppPageHtmlResponsePolicyOptions, ResolveAppPageRscResponsePolicyOptions, buildAppPageHtmlResponse, buildAppPageRscResponse, mergeMiddlewareResponseHeaders, resolveAppPageHtmlResponsePolicy, resolveAppPageRscResponsePolicy };
51
62
  //# sourceMappingURL=app-page-response.d.ts.map
@@ -13,6 +13,7 @@ function applyTimingHeader(headers, timing) {
13
13
  }
14
14
  function resolveAppPageRscResponsePolicy(options) {
15
15
  if (options.isForceDynamic || options.dynamicUsedDuringBuild) return { cacheControl: NO_STORE_CACHE_CONTROL };
16
+ if (options.revalidateSeconds === 0) return { cacheControl: NO_STORE_CACHE_CONTROL };
16
17
  if ((options.isForceStatic || options.isDynamicError) && !options.revalidateSeconds || options.revalidateSeconds === Infinity) return {
17
18
  cacheControl: STATIC_CACHE_CONTROL,
18
19
  cacheState: "STATIC"
@@ -28,7 +29,11 @@ function resolveAppPageHtmlResponsePolicy(options) {
28
29
  cacheControl: NO_STORE_CACHE_CONTROL,
29
30
  shouldWriteToCache: false
30
31
  };
31
- if ((options.isForceStatic || options.isDynamicError) && (options.revalidateSeconds === null || options.revalidateSeconds === 0)) return {
32
+ if (options.revalidateSeconds === 0) return {
33
+ cacheControl: NO_STORE_CACHE_CONTROL,
34
+ shouldWriteToCache: false
35
+ };
36
+ if ((options.isForceStatic || options.isDynamicError) && options.revalidateSeconds === null) return {
32
37
  cacheControl: STATIC_CACHE_CONTROL,
33
38
  cacheState: "STATIC",
34
39
  shouldWriteToCache: false
@@ -49,6 +54,24 @@ function resolveAppPageHtmlResponsePolicy(options) {
49
54
  };
50
55
  return { shouldWriteToCache: false };
51
56
  }
57
+ /**
58
+ * Merge middleware response headers into a target Headers object.
59
+ *
60
+ * Set-Cookie and Vary are accumulated (append) since multiple sources can
61
+ * contribute values. All other headers use set() so middleware owns singular
62
+ * response headers like Cache-Control.
63
+ *
64
+ * Used by buildAppPageRscResponse and the generated entry for intercepting
65
+ * route and server action responses that bypass the normal page render path.
66
+ */
67
+ function mergeMiddlewareResponseHeaders(target, middlewareHeaders) {
68
+ if (!middlewareHeaders) return;
69
+ for (const [key, value] of middlewareHeaders) {
70
+ const lowerKey = key.toLowerCase();
71
+ if (lowerKey === "set-cookie" || lowerKey === "vary") target.append(key, value);
72
+ else target.set(key, value);
73
+ }
74
+ }
52
75
  function buildAppPageRscResponse(body, options) {
53
76
  const headers = new Headers({
54
77
  "Content-Type": "text/x-component; charset=utf-8",
@@ -57,11 +80,7 @@ function buildAppPageRscResponse(body, options) {
57
80
  if (options.params && Object.keys(options.params).length > 0) headers.set("X-Vinext-Params", encodeURIComponent(JSON.stringify(options.params)));
58
81
  if (options.policy.cacheControl) headers.set("Cache-Control", options.policy.cacheControl);
59
82
  if (options.policy.cacheState) headers.set("X-Vinext-Cache", options.policy.cacheState);
60
- if (options.middlewareContext.headers) for (const [key, value] of options.middlewareContext.headers) {
61
- const lowerKey = key.toLowerCase();
62
- if (lowerKey === "set-cookie" || lowerKey === "vary") headers.append(key, value);
63
- else headers.set(key, value);
64
- }
83
+ mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);
65
84
  applyTimingHeader(headers, options.timing);
66
85
  return new Response(body, {
67
86
  status: options.middlewareContext.status ?? 200,
@@ -85,6 +104,6 @@ function buildAppPageHtmlResponse(body, options) {
85
104
  });
86
105
  }
87
106
  //#endregion
88
- export { buildAppPageHtmlResponse, buildAppPageRscResponse, resolveAppPageHtmlResponsePolicy, resolveAppPageRscResponsePolicy };
107
+ export { buildAppPageHtmlResponse, buildAppPageRscResponse, mergeMiddlewareResponseHeaders, resolveAppPageHtmlResponsePolicy, resolveAppPageRscResponsePolicy };
89
108
 
90
109
  //# sourceMappingURL=app-page-response.js.map