dinou 9.3.0 → 10.0.1

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 (166) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/README.md +157 -132
  3. package/dinou/adapters/bun.js +34 -5
  4. package/dinou/adapters/cloudflare.js +110 -17
  5. package/dinou/adapters/deno.js +46 -8
  6. package/dinou/adapters/netlify.js +86 -50
  7. package/dinou/adapters/node.js +8 -0
  8. package/dinou/assets.d.ts +32 -5
  9. package/dinou/bun/build.js +190 -106
  10. package/dinou/cli.js +992 -532
  11. package/dinou/cloudflare/build.js +187 -106
  12. package/dinou/compiled/autoprefixer/index.js +509 -517
  13. package/dinou/compiled/babel-core/index.js +738 -716
  14. package/dinou/compiled/babel-generator/index.js +341 -299
  15. package/dinou/compiled/babel-loader/index.js +766 -744
  16. package/dinou/compiled/babel-parser/index.js +2 -2
  17. package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
  18. package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
  19. package/dinou/compiled/babel-preset-react/index.js +752 -730
  20. package/dinou/compiled/babel-preset-typescript/index.js +738 -716
  21. package/dinou/compiled/babel-traverse/index.js +463 -433
  22. package/dinou/compiled/babel-types/index.js +176 -176
  23. package/dinou/compiled/chokidar/index.js +4 -4
  24. package/dinou/compiled/commander/index.js +15 -15
  25. package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
  26. package/dinou/compiled/css-loader/index.js +289 -289
  27. package/dinou/compiled/css-loader/runtime/api.js +85 -0
  28. package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
  29. package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
  30. package/dinou/compiled/css-loader/runtime/package.json +3 -0
  31. package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
  32. package/dinou/compiled/fast-glob/index.js +5810 -0
  33. package/dinou/compiled/generic-names/index.js +16 -16
  34. package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js → chunk-R6DP5ZYM.js} +36 -36
  35. package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
  36. package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
  37. package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
  38. package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
  39. package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
  40. package/dinou/compiled/postcss/index.js +83 -83
  41. package/dinou/compiled/postcss-import/index.js +147 -117
  42. package/dinou/compiled/postcss-modules/index.js +216 -216
  43. package/dinou/compiled/resolve/index.js +1224 -0
  44. package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
  45. package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
  46. package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
  47. package/dinou/compiled/rollup-plugin-json/index.js +22 -18
  48. package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
  49. package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
  50. package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
  51. package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
  52. package/dinou/compiled/vendors-manifest.json +59 -83
  53. package/dinou/core/asset-extensions.js +482 -33
  54. package/dinou/core/bailout-proxy.js +21 -2
  55. package/dinou/core/build-static-pages.js +523 -371
  56. package/dinou/core/builtin-asset-extensions.js +63 -0
  57. package/dinou/core/cache-revalidate.js +449 -256
  58. package/dinou/core/cache-slot.js +289 -79
  59. package/dinou/core/client-webpack.jsx +470 -39
  60. package/dinou/core/client.jsx +402 -39
  61. package/dinou/core/config.js +3 -0
  62. package/dinou/core/copy-static-dirs.js +98 -0
  63. package/dinou/core/createScopedName.js +22 -4
  64. package/dinou/core/dinou-paths.js +1 -1
  65. package/dinou/core/discover-layouts.js +200 -0
  66. package/dinou/core/edge-ssr.js +1 -1
  67. package/dinou/core/ensure-vendor-mode.js +78 -19
  68. package/dinou/core/env.js +544 -0
  69. package/dinou/core/export-static.js +41 -9
  70. package/dinou/core/generate-route-types.js +989 -95
  71. package/dinou/core/generate-static-rsc.js +5 -6
  72. package/dinou/core/generate-static.js +45 -6
  73. package/dinou/core/get-abs-path-with-ext.js +217 -75
  74. package/dinou/core/get-asset-from-manifest.js +19 -8
  75. package/dinou/core/get-error-jsx.js +4 -5
  76. package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
  77. package/dinou/core/get-jsx.js +220 -53
  78. package/dinou/core/handler.js +1647 -466
  79. package/dinou/core/import-module.js +7 -0
  80. package/dinou/core/layout-functions.js +72 -13
  81. package/dinou/core/link.jsx +34 -6
  82. package/dinou/core/load-dinou-config.js +520 -89
  83. package/dinou/core/manifest-provider.js +4 -14
  84. package/dinou/core/navigation-utils.js +141 -3
  85. package/dinou/core/navigation.js +134 -50
  86. package/dinou/core/node-middleware-runner.js +165 -0
  87. package/dinou/core/postcss-pipeline.js +236 -0
  88. package/dinou/core/ppr-context.js +114 -22
  89. package/dinou/core/ppr-runtime.js +391 -127
  90. package/dinou/core/redirect.jsx +1 -1
  91. package/dinou/core/render-jsx-to-client-jsx.js +216 -48
  92. package/dinou/core/request-context.js +59 -3
  93. package/dinou/core/resolve-contextual-dinou.js +523 -0
  94. package/dinou/core/resolve-setup-files.js +85 -27
  95. package/dinou/core/revalidating.js +10 -2
  96. package/dinou/core/route-generator.js +6 -2
  97. package/dinou/core/rsc-renderer.js +4 -1
  98. package/dinou/core/run-ssg.js +6 -0
  99. package/dinou/core/runtime-env.js +265 -0
  100. package/dinou/core/server-css-modules-plugin.js +155 -0
  101. package/dinou/core/server-function-proxy-webpack.js +27 -2
  102. package/dinou/core/server-function-proxy.js +27 -2
  103. package/dinou/core/slot.js +47 -2
  104. package/dinou/core/static-assets.js +503 -0
  105. package/dinou/core/storage-adapter.js +452 -24
  106. package/dinou/core/transform-server-functions.js +272 -24
  107. package/dinou/core/tsconfig-aliases.js +964 -0
  108. package/dinou/core/uneject.js +640 -0
  109. package/dinou/core/url-resolver.js +1 -1
  110. package/dinou/core/vfs.js +11 -2
  111. package/dinou/css.d.ts +4 -1
  112. package/dinou/deno/build.js +205 -153
  113. package/dinou/deno/seed-kv.js +4 -0
  114. package/dinou/env.d.ts +22 -2
  115. package/dinou/esbuild/build.js +40 -50
  116. package/dinou/esbuild/dev.js +33 -7
  117. package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
  118. package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
  119. package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
  120. package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
  121. package/dinou/esbuild/helpers-esbuild/write.js +13 -3
  122. package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
  123. package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
  124. package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
  125. package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
  126. package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
  127. package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
  128. package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
  129. package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
  130. package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
  131. package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
  132. package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
  133. package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
  134. package/dinou/index.d.ts +1028 -88
  135. package/dinou/node/build.js +138 -74
  136. package/dinou/node/bundle-dual-engine.js +393 -131
  137. package/dinou/node/dev.js +1005 -275
  138. package/dinou/package.json +11 -34
  139. package/dinou/rollup/postcss.config.js +3 -4
  140. package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
  141. package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
  142. package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
  143. package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
  144. package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
  145. package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
  146. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
  147. package/dinou/rollup/rollup.config.js +174 -101
  148. package/dinou/scripts/build-vendors.js +123 -33
  149. package/dinou/server.d.ts +126 -15
  150. package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
  151. package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
  152. package/dinou/webpack/loaders/server-functions-loader.js +1 -1
  153. package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
  154. package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
  155. package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
  156. package/dinou/webpack/postcss.config.js +3 -4
  157. package/dinou/webpack/webpack.config.js +408 -132
  158. package/eject.js +6 -224
  159. package/package.json +7 -9
  160. package/dinou/compiled/cross-env/index.js +0 -661
  161. package/dinou/compiled/dotenv/index.js +0 -375
  162. package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
  163. package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
  164. package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
  165. package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
  166. package/dinou/compiled/tsconfig-paths-webpack-plugin/index.js +0 -3956
@@ -1,48 +1,30 @@
1
1
  import path from "node:path";
2
- import { existsSync, readdirSync, mkdirSync, rmSync } from "node:fs";
2
+ import { existsSync, readdirSync } from "node:fs";
3
3
  import React from "react";
4
4
  import { asyncRenderJSXToClientJSX } from "./render-jsx-to-client-jsx.js";
5
5
  import { getFilePathAndDynamicParams } from "./get-file-path-and-dynamic-params.js";
6
6
  import importModule from "./import-module.js";
7
7
  import { requestStorage } from "./request-context.js";
8
- import { getLayoutProps, resolveLayoutFunctionsConfig, getLayoutFunctionsPath } from "./layout-functions.js";
9
- import { runWithPprContext, getRegisteredHoles, resetPprHoles } from "./ppr-context.js";
8
+ import { createUnifiedEnv } from "./runtime-env.js";
9
+ import { getLayoutProps, resolveLayoutFunctionsConfig, getLayoutFunctionsPath, resolveLayoutChainPpr } from "./layout-functions.js";
10
+ import { runWithPprContext, getRegisteredHoles, resetPprHoles, markPageRootElement, markLayoutRootElement } from "./ppr-context.js";
10
11
  import { resolveModulePpr } from "./resolve-module-ppr.js";
11
- import { getDinouConfig } from "./load-dinou-config.js";
12
12
  import { createBailoutProxy } from "./bailout-proxy.js";
13
+ import { sortEntriesByName } from "./discover-layouts.js";
13
14
 
14
15
  async function resolveBuildPprForRoute(segments, pagePath, pageFunctionsPath, srcFolder) {
15
- const globalCfg = await getDinouConfig();
16
- let inheritedPpr = Boolean(globalCfg?.ppr);
17
- try {
18
- const parentLayouts = getFilePathAndDynamicParams(
19
- segments || [],
20
- {},
21
- srcFolder,
22
- "layout",
23
- true,
24
- false,
25
- undefined,
26
- 0,
27
- {},
28
- true
29
- );
30
- if (parentLayouts && Array.isArray(parentLayouts)) {
31
- for (const [lPath, lParams] of parentLayouts) {
32
- const lConfig = await resolveLayoutFunctionsConfig(lPath, lParams);
33
- if (lConfig && lConfig.ppr !== null && lConfig.ppr !== undefined) {
34
- inheritedPpr = Boolean(lConfig.ppr);
35
- }
36
- }
37
- }
38
- } catch (e) {}
16
+ const { layoutPprMap, defaultPpr, anyLayoutPpr } = await resolveLayoutChainPpr(
17
+ segments || [],
18
+ {},
19
+ srcFolder,
20
+ );
39
21
 
40
22
  let explicitPagePpr = null;
41
23
  if (pageFunctionsPath) {
42
24
  try {
43
25
  const module = await importModule(pageFunctionsPath);
44
26
  explicitPagePpr = await resolveModulePpr(module);
45
- } catch (e) {}
27
+ } catch (e) { }
46
28
  }
47
29
  if (explicitPagePpr === null && typeof globalThis !== "undefined" && globalThis.__DINOU_ROUTE_METADATA__) {
48
30
  const normKey = pageFunctionsPath ? pageFunctionsPath.replace(/\\/g, "/") : "";
@@ -54,7 +36,11 @@ async function resolveBuildPprForRoute(segments, pagePath, pageFunctionsPath, sr
54
36
  }
55
37
  }
56
38
 
57
- return explicitPagePpr !== null ? explicitPagePpr : inheritedPpr;
39
+ const pageEffectivePpr =
40
+ explicitPagePpr !== null ? explicitPagePpr : Boolean(defaultPpr);
41
+ const isRoutePpr = Boolean(pageEffectivePpr || anyLayoutPpr);
42
+
43
+ return { isRoutePpr, pageEffectivePpr, layoutPprMap };
58
44
  }
59
45
 
60
46
  const staticRoutes = new Set();
@@ -97,7 +83,7 @@ async function buildStaticPages(onProgress = null) {
97
83
  dynamicStructure = [],
98
84
  doNotPushAtEnd = false,
99
85
  ) {
100
- const entries = readdirSync(currentPath, { withFileTypes: true });
86
+ const entries = sortEntriesByName(readdirSync(currentPath, { withFileTypes: true }));
101
87
  const pages = [];
102
88
 
103
89
  // 🛡️ Descubrir layout en esta carpeta si existe
@@ -165,12 +151,38 @@ async function buildStaticPages(onProgress = null) {
165
151
  let revalidate, getStaticPaths;
166
152
  if (pageFunctionsPath) {
167
153
  const module = await importModule(pageFunctionsPath);
168
- getStaticPaths = module.getStaticPaths || module.default?.getStaticPaths;
169
- revalidate = module.revalidate || module.default?.revalidate;
154
+ const defMod = module.default?.default ? module.default.default : module.default;
155
+ getStaticPaths = module.getStaticPaths || defMod?.getStaticPaths;
156
+ revalidate = module.revalidate ?? defMod?.revalidate;
157
+ }
158
+ const lfPath = getLayoutFunctionsPath(dynamicPath);
159
+ if (lfPath) {
160
+ const lmod = await importModule(lfPath);
161
+ const ldefMod = lmod.default?.default ? lmod.default.default : lmod.default;
162
+ const lmodGetStaticPaths = lmod.getStaticPaths || ldefMod?.getStaticPaths;
163
+ const lmodRevalidate = lmod.revalidate ?? ldefMod?.revalidate;
164
+ if (!getStaticPaths && lmodGetStaticPaths) {
165
+ getStaticPaths = lmodGetStaticPaths;
166
+ }
167
+ if (revalidate === undefined && lmodRevalidate !== undefined) {
168
+ revalidate = lmodRevalidate;
169
+ }
170
170
  }
171
171
  const isLocalPage =
172
172
  pagePath && path.dirname(pagePath) === dynamicPath;
173
- if (isLocalPage && !(await isDynamicRoute(revalidate))) {
173
+ const [layoutPath] = getFilePathAndDynamicParams(
174
+ segments,
175
+ {},
176
+ dynamicPath,
177
+ "layout",
178
+ true,
179
+ true,
180
+ undefined,
181
+ segments.length,
182
+ );
183
+ const hasLocalLayout =
184
+ layoutPath && path.dirname(layoutPath) === dynamicPath;
185
+ if ((isLocalPage || hasLocalLayout) && !(await isDynamicRoute(revalidate))) {
174
186
  if (process.env.DINOU_DEBUG) {
175
187
  console.log(
176
188
  `Found optional catch-all route: ${segments.join("/") ?? ""
@@ -237,10 +249,10 @@ async function buildStaticPages(onProgress = null) {
237
249
  }
238
250
 
239
251
  // 🛡️ 3. URL CLEANING
240
- // Remove undefineds for the physical URL
241
- const validSegmentsToAdd = flatSegments.filter(
242
- (s) => s !== undefined && s !== null && s !== "",
243
- );
252
+ // Remove undefineds for the physical URL and coerce numeric segments to strings
253
+ const validSegmentsToAdd = flatSegments
254
+ .filter((s) => s !== undefined && s !== null && s !== "")
255
+ .map((s) => String(s));
244
256
 
245
257
  // 🛡️ 4. PARAMS PREPARATION & NORMALIZATION
246
258
  const paramsToAdd = isObject
@@ -310,12 +322,38 @@ async function buildStaticPages(onProgress = null) {
310
322
  let revalidate, getStaticPaths;
311
323
  if (pageFunctionsPath) {
312
324
  const module = await importModule(pageFunctionsPath);
313
- getStaticPaths = module.getStaticPaths || module.default?.getStaticPaths;
314
- revalidate = module.revalidate || module.default?.revalidate;
325
+ const defMod = module.default?.default ? module.default.default : module.default;
326
+ getStaticPaths = module.getStaticPaths || defMod?.getStaticPaths;
327
+ revalidate = module.revalidate ?? defMod?.revalidate;
328
+ }
329
+ const lfPath = getLayoutFunctionsPath(dynamicPath);
330
+ if (lfPath) {
331
+ const lmod = await importModule(lfPath);
332
+ const ldefMod = lmod.default?.default ? lmod.default.default : lmod.default;
333
+ const lmodGetStaticPaths = lmod.getStaticPaths || ldefMod?.getStaticPaths;
334
+ const lmodRevalidate = lmod.revalidate ?? ldefMod?.revalidate;
335
+ if (!getStaticPaths && lmodGetStaticPaths) {
336
+ getStaticPaths = lmodGetStaticPaths;
337
+ }
338
+ if (revalidate === undefined && lmodRevalidate !== undefined) {
339
+ revalidate = lmodRevalidate;
340
+ }
315
341
  }
316
342
  const isLocalPage =
317
343
  pagePath && path.dirname(pagePath) === dynamicPath;
318
- if (isLocalPage && !(await isDynamicRoute(revalidate))) {
344
+ const [layoutPath] = getFilePathAndDynamicParams(
345
+ segments,
346
+ {},
347
+ dynamicPath,
348
+ "layout",
349
+ true,
350
+ true,
351
+ undefined,
352
+ segments.length,
353
+ );
354
+ const hasLocalLayout =
355
+ layoutPath && path.dirname(layoutPath) === dynamicPath;
356
+ if ((isLocalPage || hasLocalLayout) && !(await isDynamicRoute(revalidate))) {
319
357
  if (process.env.DINOU_DEBUG) {
320
358
  console.log(
321
359
  `Found catch-all route: ${segments.join("/") ?? ""
@@ -360,8 +398,11 @@ async function buildStaticPages(onProgress = null) {
360
398
  }
361
399
 
362
400
  // 🛡️ FIX 2: Segment filtering.
363
- // Flatten (.flat) to handle the catch-all array and filter undefineds from parents.
364
- const validSegmentsToAdd = segmentsToAdd.flat();
401
+ // Flatten (.flat) to handle the catch-all array, filter empties, and coerce numbers to strings.
402
+ const validSegmentsToAdd = segmentsToAdd
403
+ .flat()
404
+ .filter((s) => s !== undefined && s !== null && s !== "")
405
+ .map((s) => String(s));
365
406
 
366
407
  const paramsToAdd = isObject
367
408
  ? pathItem
@@ -418,12 +459,38 @@ async function buildStaticPages(onProgress = null) {
418
459
  let revalidate, getStaticPaths;
419
460
  if (pageFunctionsPath) {
420
461
  const module = await importModule(pageFunctionsPath);
421
- getStaticPaths = module.getStaticPaths || module.default?.getStaticPaths;
422
- revalidate = module.revalidate || module.default?.revalidate;
462
+ const defMod = module.default?.default ? module.default.default : module.default;
463
+ getStaticPaths = module.getStaticPaths || defMod?.getStaticPaths;
464
+ revalidate = module.revalidate ?? defMod?.revalidate;
465
+ }
466
+ const lfPath = getLayoutFunctionsPath(dynamicPath);
467
+ if (lfPath) {
468
+ const lmod = await importModule(lfPath);
469
+ const ldefMod = lmod.default?.default ? lmod.default.default : lmod.default;
470
+ const lmodGetStaticPaths = lmod.getStaticPaths || ldefMod?.getStaticPaths;
471
+ const lmodRevalidate = lmod.revalidate ?? ldefMod?.revalidate;
472
+ if (!getStaticPaths && lmodGetStaticPaths) {
473
+ getStaticPaths = lmodGetStaticPaths;
474
+ }
475
+ if (revalidate === undefined && lmodRevalidate !== undefined) {
476
+ revalidate = lmodRevalidate;
477
+ }
423
478
  }
424
479
  const isLocalPage =
425
480
  pagePath && path.dirname(pagePath) === dynamicPath;
426
- if (isLocalPage && !(await isDynamicRoute(revalidate))) {
481
+ const [layoutPath] = getFilePathAndDynamicParams(
482
+ segments,
483
+ {},
484
+ dynamicPath,
485
+ "layout",
486
+ true,
487
+ true,
488
+ undefined,
489
+ segments.length,
490
+ );
491
+ const hasLocalLayout =
492
+ layoutPath && path.dirname(layoutPath) === dynamicPath;
493
+ if ((isLocalPage || hasLocalLayout) && !(await isDynamicRoute(revalidate))) {
427
494
  if (process.env.DINOU_DEBUG) {
428
495
  console.log(
429
496
  `Found optional dynamic route: ${segments.join("/") ?? ""
@@ -482,9 +549,9 @@ async function buildStaticPages(onProgress = null) {
482
549
  }
483
550
 
484
551
  // 🛡️ 3. URL CLEANING
485
- const validSegmentsToAdd = flatSegments.filter(
486
- (s) => s !== undefined && s !== null && s !== "",
487
- );
552
+ const validSegmentsToAdd = flatSegments
553
+ .filter((s) => s !== undefined && s !== null && s !== "")
554
+ .map((s) => String(s));
488
555
 
489
556
  // 🛡️ 4. PARAMS PREPARATION
490
557
  // Here we DO NOT normalize to [], because it is a single parameter.
@@ -547,13 +614,14 @@ async function buildStaticPages(onProgress = null) {
547
614
  const module = await importModule(pageFunctionsPath);
548
615
  const defMod = module.default?.default ? module.default.default : module.default;
549
616
  getStaticPaths = module.getStaticPaths || defMod?.getStaticPaths;
550
- revalidate = module.revalidate || defMod?.revalidate;
617
+ revalidate = module.revalidate ?? defMod?.revalidate;
551
618
  }
552
619
  const lfPath = getLayoutFunctionsPath(dynamicPath);
553
620
  if (lfPath) {
554
621
  const lmod = await importModule(lfPath);
555
- const lmodGetStaticPaths = lmod.getStaticPaths || lmod.default?.getStaticPaths;
556
- const lmodRevalidate = lmod.revalidate || lmod.default?.revalidate;
622
+ const ldefMod = lmod.default?.default ? lmod.default.default : lmod.default;
623
+ const lmodGetStaticPaths = lmod.getStaticPaths || ldefMod?.getStaticPaths;
624
+ const lmodRevalidate = lmod.revalidate ?? ldefMod?.revalidate;
557
625
  if (!getStaticPaths && lmodGetStaticPaths) {
558
626
  getStaticPaths = lmodGetStaticPaths;
559
627
  }
@@ -594,6 +662,26 @@ async function buildStaticPages(onProgress = null) {
594
662
  let segmentsToAdd;
595
663
 
596
664
  if (isObject) {
665
+ let parentParamMismatch = false;
666
+ for (const [boundKey, boundVal] of Object.entries(params)) {
667
+ if (
668
+ Object.prototype.hasOwnProperty.call(pathItem, boundKey) &&
669
+ !currentStructure.includes(boundKey)
670
+ ) {
671
+ const normItem = Array.isArray(pathItem[boundKey])
672
+ ? pathItem[boundKey].join(",")
673
+ : String(pathItem[boundKey] ?? "");
674
+ const normBound = Array.isArray(boundVal)
675
+ ? boundVal.join(",")
676
+ : String(boundVal ?? "");
677
+ if (normItem !== normBound) {
678
+ parentParamMismatch = true;
679
+ break;
680
+ }
681
+ }
682
+ }
683
+ if (parentParamMismatch) continue;
684
+
597
685
  let notValidRoute = false;
598
686
  segmentsToAdd = currentStructure.map((key, i, arr) => {
599
687
  const isObject = typeof key === "object" && key !== null;
@@ -616,7 +704,10 @@ async function buildStaticPages(onProgress = null) {
616
704
  segmentsToAdd = [pathItem];
617
705
  }
618
706
 
619
- const validSegmentsToAdd = segmentsToAdd.flat();
707
+ const validSegmentsToAdd = segmentsToAdd
708
+ .flat()
709
+ .filter((s) => s !== undefined && s !== null && s !== "")
710
+ .map((s) => String(s));
620
711
 
621
712
  const paramsToAdd = isObject
622
713
  ? pathItem
@@ -674,7 +765,7 @@ async function buildStaticPages(onProgress = null) {
674
765
  const module = await importModule(pageFunctionsPath);
675
766
  const defMod = module.default?.default ? module.default.default : module.default;
676
767
  getStaticPaths = module.getStaticPaths || defMod?.getStaticPaths;
677
- revalidate = module.revalidate || defMod?.revalidate;
768
+ revalidate = module.revalidate ?? defMod?.revalidate;
678
769
  }
679
770
  const isLocalPage =
680
771
  pagePath && path.dirname(pagePath) === dynamicPath;
@@ -686,8 +777,12 @@ async function buildStaticPages(onProgress = null) {
686
777
  : getStaticPaths);
687
778
  for (const pathItem of paths) {
688
779
  const currentStructure = dynamicStructure;
780
+ const dynamicKeys = currentStructure.filter((k) => typeof k === "string");
781
+ const targetParamName = dynamicKeys[dynamicKeys.length - 1];
689
782
  const isObject =
690
- typeof pathItem === "object" && pathItem !== null;
783
+ typeof pathItem === "object" &&
784
+ pathItem !== null &&
785
+ !Array.isArray(pathItem);
691
786
 
692
787
  let segmentsToAdd;
693
788
 
@@ -712,14 +807,23 @@ async function buildStaticPages(onProgress = null) {
712
807
  });
713
808
  if (notValidRoute) continue;
714
809
  } else {
715
- segmentsToAdd = [pathItem];
810
+ segmentsToAdd = currentStructure.map((key) =>
811
+ typeof key === "object" && key !== null
812
+ ? key.STATIC_PARAM_NAME
813
+ : pathItem,
814
+ );
716
815
  }
717
816
 
718
- const validSegmentsToAdd = segmentsToAdd.flat();
817
+ const validSegmentsToAdd = segmentsToAdd
818
+ .flat()
819
+ .filter((s) => s !== undefined && s !== null && s !== "")
820
+ .map((s) => String(s));
719
821
 
720
822
  const paramsToAdd = isObject
721
823
  ? pathItem
722
- : { [paramName]: pathItem };
824
+ : targetParamName
825
+ ? { [targetParamName]: pathItem }
826
+ : {};
723
827
 
724
828
  pages.push(
725
829
  ...(await collectPages(
@@ -784,11 +888,13 @@ async function buildStaticPages(onProgress = null) {
784
888
  if (pageFunctionsPath) {
785
889
  try {
786
890
  const module = await importModule(pageFunctionsPath);
787
- revalidate = module.revalidate || module.default?.revalidate;
788
- } catch (e) {}
891
+ const defMod = module.default?.default ? module.default.default : module.default;
892
+ revalidate = module.revalidate ?? defMod?.revalidate;
893
+ } catch (e) { }
789
894
  }
790
895
 
791
- const isPpr = await resolveBuildPprForRoute(segments, pagePath, pageFunctionsPath, srcFolder);
896
+ const { isRoutePpr: isPpr, pageEffectivePpr, layoutPprMap } =
897
+ await resolveBuildPprForRoute(segments, pagePath, pageFunctionsPath, srcFolder);
792
898
 
793
899
  if (pagePath && (!(await isDynamicRoute(revalidate)) || isPpr) && !doNotPushAtEnd) {
794
900
  pages.push({
@@ -796,6 +902,8 @@ async function buildStaticPages(onProgress = null) {
796
902
  segments,
797
903
  params: dParams,
798
904
  ppr: isPpr,
905
+ pagePpr: pageEffectivePpr,
906
+ layoutPprMap,
799
907
  });
800
908
  const routeName = segments.join("/") ? "/" + segments.join("/") : "/";
801
909
  if (typeof onProgress === "function") {
@@ -813,7 +921,14 @@ async function buildStaticPages(onProgress = null) {
813
921
  const pages = await collectPages(srcFolder);
814
922
 
815
923
  let pageIdx = 0;
816
- for (const { path: folderPath, segments, params, ppr: pageIsPpr } of pages) {
924
+ for (const {
925
+ path: folderPath,
926
+ segments,
927
+ params,
928
+ ppr: pageIsPpr,
929
+ pagePpr: pageEffectivePpr,
930
+ layoutPprMap,
931
+ } of pages) {
817
932
  pageIdx++;
818
933
  try {
819
934
  const reqPath = segments.length ? "/" + segments.join("/") + "/" : "/";
@@ -825,6 +940,7 @@ async function buildStaticPages(onProgress = null) {
825
940
  // ====================================================================
826
941
  // Although contract says it returns void, internally we save
827
942
  // the state in case you want to log errors (ex: a redirect in build time).
943
+ let mockContext;
828
944
  const mockRes = {
829
945
  _statusCode: 200,
830
946
  _headers: {},
@@ -867,6 +983,7 @@ async function buildStaticPages(onProgress = null) {
867
983
 
868
984
  this._statusCode = status;
869
985
  this._redirectUrl = url;
986
+ if (mockContext) mockContext._hasRedirected = true;
870
987
 
871
988
  // Log warning because a redirect in SSG is usually problematic
872
989
  if (process.env.DINOU_DEBUG) {
@@ -900,19 +1017,25 @@ async function buildStaticPages(onProgress = null) {
900
1017
  // ====================================================================
901
1018
  // 2. MOCK REQ: Fulfilling RequestContextStore['req']
902
1019
  // ====================================================================
1020
+ const unifiedEnv = createUnifiedEnv();
903
1021
  const mockReq = {
904
1022
  query: queryProxy,
905
1023
  cookies: cookiesProxy,
906
1024
  headers: headersProxy,
907
1025
  path: reqPath,
908
1026
  method: "GET",
1027
+ env: unifiedEnv,
1028
+ ctx: null,
909
1029
  };
910
1030
 
911
1031
  // 3. FULL CONTEXT
912
- const mockContext = {
1032
+ mockContext = {
913
1033
  req: mockReq,
914
1034
  res: mockRes,
1035
+ env: unifiedEnv,
1036
+ ctx: null,
915
1037
  _markDynamic: markAsDynamic,
1038
+ _hasRedirected: false,
916
1039
  };
917
1040
 
918
1041
  let revalidate;
@@ -921,174 +1044,196 @@ async function buildStaticPages(onProgress = null) {
921
1044
  const jsx = await requestStorage.run(mockContext, async () => {
922
1045
  return await runWithPprContext({ isPpr: Boolean(pageIsPpr) }, async () => {
923
1046
  const [pagePath] = getFilePathAndDynamicParams(
924
- segments,
925
- {},
926
- folderPath,
927
- "page",
928
- true,
929
- true,
930
- undefined,
931
- segments.length,
932
- );
933
- const pageModule = await importModule(pagePath);
934
- const Page = pageModule.default ?? pageModule;
935
-
936
- let props = { params };
937
-
938
- const [pageFunctionsPath] = getFilePathAndDynamicParams(
939
- segments,
940
- {},
941
- folderPath,
942
- "page_functions",
943
- true,
944
- true,
945
- undefined,
946
- segments.length,
947
- );
948
-
949
- let pageFunctionsProps;
950
-
951
- if (pageFunctionsPath) {
952
- const pageFunctionsModule = await importModule(pageFunctionsPath);
953
- const defMod = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
954
- const getProps = pageFunctionsModule.getProps || defMod?.getProps;
955
- revalidate = pageFunctionsModule.revalidate || defMod?.revalidate;
956
- const rawTags = pageFunctionsModule.getCacheTags ?? defMod?.getCacheTags;
957
- if (typeof rawTags === "function") {
958
- try {
959
- cacheTags = await rawTags(params);
960
- } catch (e) {
961
- console.error("Error running getCacheTags in buildStaticPages:", e);
962
- }
963
- } else if (Array.isArray(rawTags)) {
964
- cacheTags = rawTags;
965
- }
966
- pageFunctionsProps = await getProps?.(params);
967
- props = { ...props, ...(pageFunctionsProps ?? {}) };
968
- }
969
-
970
- let jsx = React.createElement(Page, props);
971
- jsx = { ...jsx, __modulePath: pagePath };
972
-
973
- // Resolve and nest layout components from the page folder up to the source root
974
- const noLayoutPath = path.join(folderPath, "no_layout");
975
- if (!existsSync(noLayoutPath)) {
976
- const layouts = getFilePathAndDynamicParams(
977
1047
  segments,
978
1048
  {},
979
- srcFolder,
980
- "layout",
1049
+ folderPath,
1050
+ "page",
1051
+ true,
981
1052
  true,
982
- false,
983
1053
  undefined,
984
- 0,
1054
+ segments.length,
1055
+ );
1056
+ const pageModule = await importModule(pagePath);
1057
+ const Page = pageModule.default ?? pageModule;
1058
+
1059
+ let props = { params };
1060
+
1061
+ const [pageFunctionsPath] = getFilePathAndDynamicParams(
1062
+ segments,
985
1063
  {},
1064
+ folderPath,
1065
+ "page_functions",
1066
+ true,
986
1067
  true,
1068
+ undefined,
1069
+ segments.length,
987
1070
  );
988
1071
 
989
- if (layouts && Array.isArray(layouts)) {
990
- let index = 0;
991
- for (const [layoutPath, dParams, slots] of layouts.reverse()) {
992
- const layoutModule = await importModule(layoutPath);
993
- const Layout = layoutModule.default ?? layoutModule;
994
- const layoutFolderPath = path.dirname(layoutPath);
995
- const resetLayoutPath = getFilePathAndDynamicParams(
996
- [],
997
- {},
998
- layoutFolderPath,
999
- "reset_layout",
1000
- false,
1001
- )[0];
1002
- const updatedSlots = {};
1003
- for (const [slotName, slotValue] of Object.entries(slots)) {
1004
- let updatedSlotElement;
1005
- const slotFilePath = slotValue?.slotPath || slotValue?.props?.__modulePath;
1006
- const slotParams = slotValue?.slotParams || slotValue?.props?.params || {};
1072
+ let pageFunctionsProps;
1007
1073
 
1008
- try {
1009
- let elementToRender;
1010
- if (slotValue && slotValue.slotPath) {
1011
- const slotModule = await importModule(slotValue.slotPath);
1012
- const Slot = slotModule.default ?? slotModule;
1013
- elementToRender = React.createElement(Slot, {
1014
- params: slotParams,
1015
- key: slotName,
1016
- __modulePath: slotValue.slotPath,
1017
- });
1018
- } else {
1019
- elementToRender = {
1020
- ...slotValue,
1021
- __modulePath: slotFilePath ?? null,
1022
- };
1023
- }
1024
- await asyncRenderJSXToClientJSX(elementToRender);
1025
- updatedSlotElement = elementToRender;
1026
- } catch (e) {
1027
- if (slotFilePath) {
1028
- const realSlotFolder = path.dirname(slotFilePath);
1029
- const [slotErrorPath, slotErrorParams] =
1030
- getFilePathAndDynamicParams(
1031
- segments,
1032
- {},
1033
- realSlotFolder,
1034
- "error",
1035
- true,
1036
- true,
1037
- undefined,
1038
- segments.length,
1039
- );
1074
+ if (pageFunctionsPath) {
1075
+ const pageFunctionsModule = await importModule(pageFunctionsPath);
1076
+ const defMod = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
1077
+ const getProps = pageFunctionsModule.getProps || defMod?.getProps;
1078
+ revalidate = pageFunctionsModule.revalidate ?? defMod?.revalidate;
1079
+ const rawTags = pageFunctionsModule.getCacheTags ?? defMod?.getCacheTags;
1080
+ if (typeof rawTags === "function") {
1081
+ try {
1082
+ cacheTags = await rawTags(params);
1083
+ } catch (e) {
1084
+ console.error("Error running getCacheTags in buildStaticPages:", e);
1085
+ }
1086
+ } else if (Array.isArray(rawTags)) {
1087
+ cacheTags = rawTags;
1088
+ }
1089
+ pageFunctionsProps = await getProps?.(params);
1090
+ if (mockRes._redirectUrl || mockContext._hasRedirected) {
1091
+ return null;
1092
+ }
1093
+ props = { ...props, ...(pageFunctionsProps ?? {}) };
1094
+ }
1040
1095
 
1041
- if (slotErrorPath) {
1042
- const slotErrorModule = await importModule(slotErrorPath);
1043
- const SlotError = slotErrorModule.default ?? slotErrorModule;
1096
+ let jsx = markPageRootElement(
1097
+ { ...React.createElement(Page, props), __modulePath: pagePath },
1098
+ Boolean(pageEffectivePpr),
1099
+ );
1044
1100
 
1045
- const serializedError = {
1046
- message: e.message || "Unknown Error",
1047
- name: e.name,
1048
- stack: process.env.NODE_ENV !== "production" ? e.stack : undefined,
1049
- };
1101
+ // Resolve and nest layout components from the page folder up to the source root
1102
+ const noLayoutPath = path.join(folderPath, "no_layout");
1103
+ if (!existsSync(noLayoutPath)) {
1104
+ const layouts = getFilePathAndDynamicParams(
1105
+ segments,
1106
+ {},
1107
+ srcFolder,
1108
+ "layout",
1109
+ true,
1110
+ false,
1111
+ undefined,
1112
+ 0,
1113
+ {},
1114
+ true,
1115
+ );
1050
1116
 
1051
- updatedSlotElement = React.createElement(SlotError, {
1052
- params: slotErrorParams,
1117
+ if (layouts && Array.isArray(layouts)) {
1118
+ let index = 0;
1119
+ for (const [layoutPath, dParams, slots] of layouts.reverse()) {
1120
+ const layoutModule = await importModule(layoutPath);
1121
+ const Layout = layoutModule.default ?? layoutModule;
1122
+ const layoutFolderPath = path.dirname(layoutPath);
1123
+ const resetLayoutPath = getFilePathAndDynamicParams(
1124
+ [],
1125
+ {},
1126
+ layoutFolderPath,
1127
+ "reset_layout",
1128
+ false,
1129
+ )[0];
1130
+ const normLayoutPath = layoutPath.replace(/\\/g, "/");
1131
+ const layoutEffectivePpr = layoutPprMap?.has(normLayoutPath)
1132
+ ? Boolean(layoutPprMap.get(normLayoutPath))
1133
+ : Boolean(pageIsPpr);
1134
+ const updatedSlots = {};
1135
+ for (const [slotName, slotValue] of Object.entries(slots)) {
1136
+ let updatedSlotElement;
1137
+ const slotFilePath = slotValue?.slotPath || slotValue?.props?.__modulePath;
1138
+ const slotParams = slotValue?.slotParams || slotValue?.props?.params || {};
1139
+
1140
+ try {
1141
+ let elementToRender;
1142
+ if (slotValue && slotValue.slotPath) {
1143
+ const slotModule = await importModule(slotValue.slotPath);
1144
+ const Slot = slotModule.default ?? slotModule;
1145
+ elementToRender = React.createElement(Slot, {
1146
+ params: slotParams,
1053
1147
  key: slotName,
1054
- error: serializedError,
1148
+ __modulePath: slotValue.slotPath,
1055
1149
  });
1056
1150
  } else {
1057
- console.warn(
1058
- `[Dinou Build] Slot @${slotName} failed and does not have error.tsx`,
1151
+ elementToRender = {
1152
+ ...slotValue,
1153
+ __modulePath: slotFilePath ?? null,
1154
+ };
1155
+ }
1156
+ elementToRender = markLayoutRootElement(
1157
+ elementToRender,
1158
+ layoutEffectivePpr,
1159
+ );
1160
+ await asyncRenderJSXToClientJSX(elementToRender);
1161
+ updatedSlotElement = elementToRender;
1162
+ } catch (e) {
1163
+ if (slotFilePath) {
1164
+ const realSlotFolder = path.dirname(slotFilePath);
1165
+ const [slotErrorPath, slotErrorParams] =
1166
+ getFilePathAndDynamicParams(
1167
+ segments,
1168
+ {},
1169
+ realSlotFolder,
1170
+ "error",
1171
+ true,
1172
+ true,
1173
+ undefined,
1174
+ segments.length,
1175
+ slotParams,
1176
+ );
1177
+
1178
+ if (slotErrorPath) {
1179
+ const slotErrorModule = await importModule(slotErrorPath);
1180
+ const SlotError = slotErrorModule.default ?? slotErrorModule;
1181
+
1182
+ const serializedError = {
1183
+ message: e.message || "Unknown Error",
1184
+ name: e.name,
1185
+ stack: process.env.NODE_ENV !== "production" ? e.stack : undefined,
1186
+ };
1187
+
1188
+ updatedSlotElement = React.createElement(SlotError, {
1189
+ params: slotErrorParams,
1190
+ key: slotName,
1191
+ error: serializedError,
1192
+ });
1193
+ } else {
1194
+ console.warn(
1195
+ `[Dinou Build] Slot @${slotName} failed and does not have error.tsx`,
1196
+ );
1197
+ updatedSlotElement = null;
1198
+ }
1199
+ } else {
1200
+ console.error(
1201
+ `[Dinou Build] Slot @${slotName} failed and has no module path`,
1059
1202
  );
1060
1203
  updatedSlotElement = null;
1061
1204
  }
1062
- } else {
1063
- console.error(
1064
- `[Dinou Build] Slot @${slotName} failed and has no module path`,
1065
- );
1066
- updatedSlotElement = null;
1205
+ }
1206
+ updatedSlots[slotName] = updatedSlotElement;
1207
+ if (mockRes._redirectUrl || mockContext._hasRedirected) {
1208
+ return null;
1067
1209
  }
1068
1210
  }
1069
- updatedSlots[slotName] = updatedSlotElement;
1070
- }
1071
- const layoutProps = await getLayoutProps(layoutPath, dParams);
1072
- let props = {
1073
- params: dParams,
1074
- ...updatedSlots,
1075
- ...(layoutProps ?? {}),
1076
- };
1077
- jsx = React.createElement(Layout, props, jsx);
1078
- jsx = { ...jsx, __modulePath: layoutPath };
1079
- if (resetLayoutPath) {
1080
- break;
1211
+ const layoutProps = await getLayoutProps(layoutPath, dParams);
1212
+ if (mockRes._redirectUrl || mockContext._hasRedirected) {
1213
+ return null;
1214
+ }
1215
+ let props = {
1216
+ params: dParams,
1217
+ ...updatedSlots,
1218
+ ...(layoutProps ?? {}),
1219
+ };
1220
+ jsx = markLayoutRootElement(
1221
+ { ...React.createElement(Layout, props, jsx), __modulePath: layoutPath },
1222
+ layoutEffectivePpr,
1223
+ );
1224
+ if (resetLayoutPath) {
1225
+ break;
1226
+ }
1227
+ index++;
1081
1228
  }
1082
- index++;
1083
1229
  }
1084
1230
  }
1085
- }
1086
1231
 
1087
- // Render the layout-nested React element tree to client-side RSC JSON format
1088
- resetPprHoles();
1089
- const renderedSingleJsx = await asyncRenderJSXToClientJSX(jsx);
1090
- capturedHoles = pageIsPpr ? getRegisteredHoles() : [];
1091
- return renderedSingleJsx;
1232
+ // Render the layout-nested React element tree to client-side RSC JSON format
1233
+ resetPprHoles();
1234
+ const renderedSingleJsx = await asyncRenderJSXToClientJSX(jsx);
1235
+ capturedHoles = pageIsPpr ? getRegisteredHoles() : [];
1236
+ return renderedSingleJsx;
1092
1237
  });
1093
1238
  });
1094
1239
 
@@ -1117,6 +1262,7 @@ async function buildStaticPages(onProgress = null) {
1117
1262
  effects: sideEffects,
1118
1263
  tags: cacheTags,
1119
1264
  ppr: Boolean(pageIsPpr),
1265
+ pagePpr: Boolean(pageEffectivePpr),
1120
1266
  holes,
1121
1267
  });
1122
1268
  if (process.env.DINOU_DEBUG) {
@@ -1143,51 +1289,25 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1143
1289
 
1144
1290
  try {
1145
1291
  const segments = reqPath.split("/").filter(Boolean);
1146
- let folderPath = srcFolder;
1147
- let dynamicParams = {};
1148
-
1149
- for (let i = 0; i < segments.length; i++) {
1150
- const segment = segments[i];
1151
- const isRouterSyntaxInSegment =
1152
- segment &&
1153
- ((segment.startsWith("(") && segment.endsWith(")")) ||
1154
- (segment.startsWith("[") && segment.endsWith("]")) ||
1155
- segment.startsWith("@") ||
1156
- segment.startsWith("_"));
1157
- const currentPath = path.join(folderPath, segment);
1158
- if (existsSync(currentPath) && !isRouterSyntaxInSegment) {
1159
- folderPath = currentPath;
1160
- continue;
1161
- }
1162
-
1163
- const entries = readdirSync(folderPath, { withFileTypes: true });
1164
- const dynamicEntry = entries.find(
1165
- (entry) =>
1166
- entry.isDirectory() &&
1167
- ((entry.name.startsWith("[") && entry.name.endsWith("]")) ||
1168
- (entry.name.startsWith("[[") && entry.name.endsWith("]]"))),
1169
- );
1170
-
1171
- if (dynamicEntry) {
1172
- folderPath = path.join(folderPath, dynamicEntry.name);
1173
- const paramName = dynamicEntry.name
1174
- .replace(/^\[\[?|\]\]?$/g, "")
1175
- .replace("...", "");
1176
- if (dynamicEntry.name.includes("...")) {
1177
- dynamicParams[paramName] = segments.slice(i).map(safeDecode);
1178
- break;
1179
- } else {
1180
- dynamicParams[paramName] = safeDecode(segment);
1181
- }
1182
- } else {
1183
- throw new Error(`No matching route found for ${reqPath}`);
1184
- }
1292
+ const [resolvedPagePath, resolvedParams] = getFilePathAndDynamicParams(
1293
+ segments,
1294
+ {},
1295
+ srcFolder,
1296
+ "page",
1297
+ true,
1298
+ true,
1299
+ );
1300
+ if (!resolvedPagePath) {
1301
+ throw new Error(`No matching route found for ${reqPath}`);
1185
1302
  }
1303
+ const folderPath = path.dirname(resolvedPagePath);
1304
+ const dynamicParams = resolvedParams || {};
1186
1305
  // ====================================================================
1187
1306
  // 1. MOCK RES: Fulfilling the ResponseProxy interface
1188
1307
  // ====================================================================
1189
1308
  // Although the contract says it returns void, internally we save
1190
1309
  // the state in case you want to log errors (e.g., a redirect at build time).
1310
+ let mockContext;
1191
1311
  const mockRes = {
1192
1312
  _statusCode: 200,
1193
1313
  _headers: {},
@@ -1230,6 +1350,7 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1230
1350
 
1231
1351
  this._statusCode = status;
1232
1352
  this._redirectUrl = url;
1353
+ if (mockContext) mockContext._hasRedirected = true;
1233
1354
 
1234
1355
  // We log a warning because a redirect in SSG is usually problematic
1235
1356
  if (process.env.DINOU_DEBUG) {
@@ -1272,15 +1393,18 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1272
1393
  };
1273
1394
 
1274
1395
  // 3. COMPLETE CONTEXT
1275
- const mockContext = {
1396
+ mockContext = {
1276
1397
  req: mockReq,
1277
1398
  res: mockRes,
1278
1399
  _markDynamic: markAsDynamic,
1400
+ _hasRedirected: false,
1279
1401
  };
1280
1402
 
1281
1403
  let revalidate;
1282
1404
  let cacheTags = [];
1283
1405
  let pageIsPpr = false;
1406
+ let pageEffectivePpr = false;
1407
+ let capturedHoles = [];
1284
1408
  const jsx = await requestStorage.run(mockContext, async () => {
1285
1409
  const [pagePath, dParams] = getFilePathAndDynamicParams(
1286
1410
  segments,
@@ -1308,151 +1432,178 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1308
1432
  segments.length,
1309
1433
  );
1310
1434
 
1311
- pageIsPpr = await resolveBuildPprForRoute(segments, pagePath, pageFunctionsPath, srcFolder);
1312
- let capturedHoles = [];
1435
+ const pprInfo = await resolveBuildPprForRoute(segments, pagePath, pageFunctionsPath, srcFolder);
1436
+ pageIsPpr = pprInfo.isRoutePpr;
1437
+ pageEffectivePpr = pprInfo.pageEffectivePpr;
1438
+ const layoutPprMap = pprInfo.layoutPprMap;
1313
1439
 
1314
1440
  return await runWithPprContext({ isPpr: pageIsPpr }, async () => {
1315
1441
  let props = { params: dParams };
1316
1442
 
1317
- let pageFunctionsProps;
1318
- if (pageFunctionsPath) {
1319
- const pageFunctionsModule = await importModule(pageFunctionsPath);
1320
- const defMod = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
1321
- const getProps = pageFunctionsModule.getProps || defMod?.getProps;
1322
- revalidate = pageFunctionsModule.revalidate || defMod?.revalidate;
1323
- if (isDynamic && (isDynamic.value = await isDynamicRoute(revalidate)))
1324
- return;
1325
- const rawTags = pageFunctionsModule.getCacheTags ?? defMod?.getCacheTags;
1326
- if (typeof rawTags === "function") {
1327
- try {
1328
- cacheTags = await rawTags(dParams);
1329
- } catch (e) {
1330
- console.error("Error running getCacheTags:", e);
1443
+ let pageFunctionsProps;
1444
+ if (pageFunctionsPath) {
1445
+ const pageFunctionsModule = await importModule(pageFunctionsPath);
1446
+ const defMod = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
1447
+ const getProps = pageFunctionsModule.getProps || defMod?.getProps;
1448
+ revalidate = pageFunctionsModule.revalidate ?? defMod?.revalidate;
1449
+ if (await isDynamicRoute(revalidate)) {
1450
+ markAsDynamic();
1451
+ if (isDynamic) isDynamic.value = true;
1452
+ return null;
1331
1453
  }
1332
- } else if (Array.isArray(rawTags)) {
1333
- cacheTags = rawTags;
1454
+ const rawTags = pageFunctionsModule.getCacheTags ?? defMod?.getCacheTags;
1455
+ if (typeof rawTags === "function") {
1456
+ try {
1457
+ cacheTags = await rawTags(dParams);
1458
+ } catch (e) {
1459
+ console.error("Error running getCacheTags:", e);
1460
+ }
1461
+ } else if (Array.isArray(rawTags)) {
1462
+ cacheTags = rawTags;
1463
+ }
1464
+ pageFunctionsProps = await getProps?.(dParams);
1465
+ if (mockRes._redirectUrl || mockContext._hasRedirected) {
1466
+ return null;
1467
+ }
1468
+ props = { ...props, ...(pageFunctionsProps ?? {}) };
1334
1469
  }
1335
- pageFunctionsProps = await getProps?.(dParams);
1336
- props = { ...props, ...(pageFunctionsProps ?? {}) };
1337
- }
1338
1470
 
1339
- let jsx = React.createElement(Page, props);
1340
- jsx = { ...jsx, __modulePath: pagePath };
1341
-
1342
- const noLayoutPath = path.join(folderPath, "no_layout");
1343
- if (!existsSync(noLayoutPath)) {
1344
- const layouts = getFilePathAndDynamicParams(
1345
- segments,
1346
- {},
1347
- srcFolder,
1348
- "layout",
1349
- true,
1350
- false,
1351
- undefined,
1352
- 0,
1353
- {},
1354
- true,
1471
+ let jsx = markPageRootElement(
1472
+ { ...React.createElement(Page, props), __modulePath: pagePath },
1473
+ Boolean(pageEffectivePpr),
1355
1474
  );
1356
- if (layouts && Array.isArray(layouts)) {
1357
- let index = 0;
1358
- for (const [layoutPath, dParams, slots] of layouts.reverse()) {
1359
- const layoutModule = await importModule(layoutPath);
1360
- const Layout = layoutModule.default ?? layoutModule;
1361
- const layoutFolderPath = path.dirname(layoutPath);
1362
- const resetLayoutPath = getFilePathAndDynamicParams(
1363
- [],
1364
- {},
1365
- layoutFolderPath,
1366
- "reset_layout",
1367
- false,
1368
- )[0];
1369
- const updatedSlots = {};
1370
- for (const [slotName, slotValue] of Object.entries(slots)) {
1371
- let updatedSlotElement;
1372
- const slotFilePath = slotValue?.slotPath || slotValue?.props?.__modulePath;
1373
- const slotParams = slotValue?.slotParams || slotValue?.props?.params || {};
1374
1475
 
1375
- try {
1376
- let elementToRender;
1377
- if (slotValue && slotValue.slotPath) {
1378
- const slotModule = await importModule(slotValue.slotPath);
1379
- const Slot = slotModule.default ?? slotModule;
1380
- elementToRender = React.createElement(Slot, {
1381
- params: slotParams,
1382
- key: slotName,
1383
- __modulePath: slotValue.slotPath,
1384
- });
1385
- } else {
1386
- elementToRender = {
1387
- ...slotValue,
1388
- __modulePath: slotFilePath ?? null,
1389
- };
1390
- }
1391
- await asyncRenderJSXToClientJSX(elementToRender);
1392
- updatedSlotElement = elementToRender;
1393
- } catch (e) {
1394
- if (slotFilePath) {
1395
- const realSlotFolder = path.dirname(slotFilePath);
1396
- const [slotErrorPath, slotErrorParams] =
1397
- getFilePathAndDynamicParams(
1398
- segments,
1399
- {},
1400
- realSlotFolder,
1401
- "error",
1402
- true, // withExtension
1403
- true, // finalDestination
1404
- undefined, // lastFound
1405
- segments.length,
1406
- );
1407
-
1408
- if (slotErrorPath) {
1409
- const slotErrorModule = await importModule(slotErrorPath);
1410
- const SlotError = slotErrorModule.default ?? slotErrorModule;
1411
-
1412
- const serializedError = {
1413
- message: e.message || "Unknown Error",
1414
- name: e.name,
1415
- stack: process.env.NODE_ENV !== "production" ? e.stack : undefined,
1416
- };
1476
+ const noLayoutPath = path.join(folderPath, "no_layout");
1477
+ if (!existsSync(noLayoutPath)) {
1478
+ const layouts = getFilePathAndDynamicParams(
1479
+ segments,
1480
+ {},
1481
+ srcFolder,
1482
+ "layout",
1483
+ true,
1484
+ false,
1485
+ undefined,
1486
+ 0,
1487
+ {},
1488
+ true,
1489
+ );
1490
+ if (layouts && Array.isArray(layouts)) {
1491
+ let index = 0;
1492
+ for (const [layoutPath, dParams, slots] of layouts.reverse()) {
1493
+ const layoutModule = await importModule(layoutPath);
1494
+ const Layout = layoutModule.default ?? layoutModule;
1495
+ const layoutFolderPath = path.dirname(layoutPath);
1496
+ const resetLayoutPath = getFilePathAndDynamicParams(
1497
+ [],
1498
+ {},
1499
+ layoutFolderPath,
1500
+ "reset_layout",
1501
+ false,
1502
+ )[0];
1503
+ const normLayoutPath = layoutPath.replace(/\\/g, "/");
1504
+ const layoutEffectivePpr = layoutPprMap?.has(normLayoutPath)
1505
+ ? Boolean(layoutPprMap.get(normLayoutPath))
1506
+ : Boolean(pageIsPpr);
1507
+ const updatedSlots = {};
1508
+ for (const [slotName, slotValue] of Object.entries(slots)) {
1509
+ let updatedSlotElement;
1510
+ const slotFilePath = slotValue?.slotPath || slotValue?.props?.__modulePath;
1511
+ const slotParams = slotValue?.slotParams || slotValue?.props?.params || {};
1417
1512
 
1418
- updatedSlotElement = React.createElement(SlotError, {
1419
- params: slotErrorParams,
1513
+ try {
1514
+ let elementToRender;
1515
+ if (slotValue && slotValue.slotPath) {
1516
+ const slotModule = await importModule(slotValue.slotPath);
1517
+ const Slot = slotModule.default ?? slotModule;
1518
+ elementToRender = React.createElement(Slot, {
1519
+ params: slotParams,
1420
1520
  key: slotName,
1421
- error: serializedError,
1521
+ __modulePath: slotValue.slotPath,
1422
1522
  });
1423
1523
  } else {
1424
- console.warn(
1425
- `[Dinou Build] Slot @${slotName} failed and does not have error.tsx`,
1524
+ elementToRender = {
1525
+ ...slotValue,
1526
+ __modulePath: slotFilePath ?? null,
1527
+ };
1528
+ }
1529
+ elementToRender = markLayoutRootElement(
1530
+ elementToRender,
1531
+ layoutEffectivePpr,
1532
+ );
1533
+ await asyncRenderJSXToClientJSX(elementToRender);
1534
+ updatedSlotElement = elementToRender;
1535
+ } catch (e) {
1536
+ if (slotFilePath) {
1537
+ const realSlotFolder = path.dirname(slotFilePath);
1538
+ const [slotErrorPath, slotErrorParams] =
1539
+ getFilePathAndDynamicParams(
1540
+ segments,
1541
+ {},
1542
+ realSlotFolder,
1543
+ "error",
1544
+ true, // withExtension
1545
+ true, // finalDestination
1546
+ undefined, // lastFound
1547
+ segments.length,
1548
+ slotParams,
1549
+ );
1550
+
1551
+ if (slotErrorPath) {
1552
+ const slotErrorModule = await importModule(slotErrorPath);
1553
+ const SlotError = slotErrorModule.default ?? slotErrorModule;
1554
+
1555
+ const serializedError = {
1556
+ message: e.message || "Unknown Error",
1557
+ name: e.name,
1558
+ stack: process.env.NODE_ENV !== "production" ? e.stack : undefined,
1559
+ };
1560
+
1561
+ updatedSlotElement = React.createElement(SlotError, {
1562
+ params: slotErrorParams,
1563
+ key: slotName,
1564
+ error: serializedError,
1565
+ });
1566
+ } else {
1567
+ console.warn(
1568
+ `[Dinou Build] Slot @${slotName} failed and does not have error.tsx`,
1569
+ );
1570
+ updatedSlotElement = null;
1571
+ }
1572
+ } else {
1573
+ console.error(
1574
+ `[Dinou Build] Slot @${slotName} failed and has no module path`,
1426
1575
  );
1427
1576
  updatedSlotElement = null;
1428
1577
  }
1429
- } else {
1430
- console.error(
1431
- `[Dinou Build] Slot @${slotName} failed and has no module path`,
1432
- );
1433
- updatedSlotElement = null;
1578
+ }
1579
+ updatedSlots[slotName] = updatedSlotElement;
1580
+ if (mockRes._redirectUrl || mockContext._hasRedirected) {
1581
+ return null;
1434
1582
  }
1435
1583
  }
1436
- updatedSlots[slotName] = updatedSlotElement;
1437
- }
1438
- let layoutProps = {
1439
- params: dParams,
1440
- ...updatedSlots,
1441
- };
1442
- const customLayoutProps = await getLayoutProps(layoutPath, dParams);
1443
- layoutProps = {
1444
- ...layoutProps,
1445
- ...(customLayoutProps ?? {}),
1446
- };
1447
- jsx = React.createElement(Layout, layoutProps, jsx);
1448
- jsx = { ...jsx, __modulePath: layoutPath };
1449
- if (resetLayoutPath) {
1450
- break;
1584
+ let layoutProps = {
1585
+ params: dParams,
1586
+ ...updatedSlots,
1587
+ };
1588
+ const customLayoutProps = await getLayoutProps(layoutPath, dParams);
1589
+ if (mockRes._redirectUrl || mockContext._hasRedirected) {
1590
+ return null;
1591
+ }
1592
+ layoutProps = {
1593
+ ...layoutProps,
1594
+ ...(customLayoutProps ?? {}),
1595
+ };
1596
+ jsx = markLayoutRootElement(
1597
+ { ...React.createElement(Layout, layoutProps, jsx), __modulePath: layoutPath },
1598
+ layoutEffectivePpr,
1599
+ );
1600
+ if (resetLayoutPath) {
1601
+ break;
1602
+ }
1603
+ index++;
1451
1604
  }
1452
- index++;
1453
1605
  }
1454
1606
  }
1455
- }
1456
1607
 
1457
1608
  resetPprHoles();
1458
1609
  const renderedSingleJsx = await asyncRenderJSXToClientJSX(jsx);
@@ -1489,6 +1640,7 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1489
1640
  effects: sideEffects,
1490
1641
  tags: cacheTags,
1491
1642
  ppr: pageIsPpr,
1643
+ pagePpr: Boolean(pageEffectivePpr),
1492
1644
  holes,
1493
1645
  });
1494
1646
  console.warn(`Registered rebuilt static page at ${reqPath}${pageIsPpr ? " (PPR)" : ""}`);