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
@@ -21,7 +21,13 @@ import { hydrateRoot } from "react-dom/client";
21
21
  import { RouterContext } from "./navigation.js";
22
22
  import { resolveUrl, isExternalUrl } from "./navigation-utils.js";
23
23
  import { createServerFunctionProxy } from "./server-function-proxy.js";
24
- import { DinouPageContext, DinouPageSlot, cleanErrorStack } from "./slot.js";
24
+ import {
25
+ DinouPageContext,
26
+ DinouPageSlot,
27
+ cleanErrorStack,
28
+ flushPendingSsrStreams,
29
+ pruneOrphanedSsrStreams,
30
+ } from "./slot.js";
25
31
 
26
32
  // ====================================================================
27
33
  // 1. GLOBAL STATE (Outside the component)
@@ -56,15 +62,97 @@ const scrollToCurrentHash = (rawHash = typeof window !== "undefined" ? window.lo
56
62
  // 2. PURE HELPERS
57
63
  // ====================================================================
58
64
 
65
+ const safeDecodeSeg = (val) => {
66
+ try {
67
+ return val ? decodeURIComponent(val) : val;
68
+ } catch (e) {
69
+ return val;
70
+ }
71
+ };
72
+
73
+ const isRouterSyntaxSeg = (rawSeg) => {
74
+ const seg = safeDecodeSeg(rawSeg);
75
+ return Boolean(
76
+ seg &&
77
+ ((seg.startsWith("(") && seg.endsWith(")")) ||
78
+ (seg.startsWith("[") && seg.endsWith("]")) ||
79
+ seg.startsWith("@") ||
80
+ seg.startsWith("_"))
81
+ );
82
+ };
83
+
84
+ const matchRoutePattern = (pSegs, uSegs, pIdx = 0, uIdx = 0) => {
85
+ if (pIdx === pSegs.length) return uIdx === uSegs.length;
86
+ const p = pSegs[pIdx];
87
+ if (p.startsWith("[[...") && p.endsWith("]]")) {
88
+ if (pIdx === pSegs.length - 1) return uIdx <= uSegs.length;
89
+ for (let k = uIdx; k <= uSegs.length; k++) {
90
+ if (matchRoutePattern(pSegs, uSegs, pIdx + 1, k)) return true;
91
+ }
92
+ return false;
93
+ }
94
+ if (p.startsWith("[...") && p.endsWith("]")) {
95
+ if (uIdx >= uSegs.length) return false;
96
+ if (pIdx === pSegs.length - 1) return true;
97
+ for (let k = uIdx + 1; k <= uSegs.length; k++) {
98
+ if (matchRoutePattern(pSegs, uSegs, pIdx + 1, k)) return true;
99
+ }
100
+ return false;
101
+ }
102
+ if (p.startsWith("[[") && p.endsWith("]]")) {
103
+ if (
104
+ uIdx < uSegs.length &&
105
+ matchRoutePattern(pSegs, uSegs, pIdx + 1, uIdx + 1)
106
+ ) {
107
+ return true;
108
+ }
109
+ return matchRoutePattern(pSegs, uSegs, pIdx + 1, uIdx);
110
+ }
111
+ if (p.startsWith("[") && p.endsWith("]")) {
112
+ if (uIdx >= uSegs.length) return false;
113
+ return matchRoutePattern(pSegs, uSegs, pIdx + 1, uIdx + 1);
114
+ }
115
+ if (uIdx >= uSegs.length || isRouterSyntaxSeg(uSegs[uIdx])) {
116
+ return false;
117
+ }
118
+ if (uSegs[uIdx] !== p && safeDecodeSeg(uSegs[uIdx]) !== p) {
119
+ return false;
120
+ }
121
+ return matchRoutePattern(pSegs, uSegs, pIdx + 1, uIdx + 1);
122
+ };
123
+
59
124
  // Helper to determine active layout folder for a pathname
60
125
  const getLayoutKey = (pathname) => {
61
126
  const rawLayouts = (typeof window !== "undefined" && window.__DINOU_LAYOUTS__) || ["", "docs"];
62
- const layouts = rawLayouts.filter((l) => typeof l === "string" && !l.startsWith("!"));
127
+ const pageRules = rawLayouts.filter((l) => typeof l === "string" && l.startsWith("="));
128
+ const layouts = rawLayouts.filter(
129
+ (l) => typeof l === "string" && !l.startsWith("!") && !l.startsWith("=")
130
+ );
63
131
  const noLayouts = rawLayouts
64
132
  .filter((l) => typeof l === "string" && l.startsWith("!"))
65
133
  .map((l) => l.slice(1));
66
134
  const cleanPath0 = pathname.split("?")[0].split("#")[0];
67
135
  const segments0 = cleanPath0.split("/").filter(Boolean);
136
+
137
+ for (const rule of pageRules) {
138
+ const colonIdx = rule.lastIndexOf(":");
139
+ if (colonIdx === -1) continue;
140
+ const pattern = rule.slice(1, colonIdx);
141
+ const spec = rule.slice(colonIdx + 1);
142
+ const pSegs = pattern ? pattern.split("/").filter(Boolean) : [];
143
+ if (matchRoutePattern(pSegs, segments0)) {
144
+ if (spec === "-1") return null;
145
+ if (spec.startsWith("*-")) {
146
+ const trailing = Number(spec.slice(2)) || 0;
147
+ const take = Math.max(0, segments0.length - trailing);
148
+ return take === 0 ? "/" : "/" + segments0.slice(0, take).join("/");
149
+ }
150
+ const depth = Number(spec);
151
+ if (depth <= 0) return "/";
152
+ return "/" + segments0.slice(0, depth).join("/");
153
+ }
154
+ }
155
+
68
156
  const fullCandidate = segments0.join("/");
69
157
  if (
70
158
  noLayouts.includes(fullCandidate) ||
@@ -137,14 +225,149 @@ const isHashChangeOnly = (finalPath) => {
137
225
  );
138
226
  };
139
227
 
228
+ const consumeInlineRscResponse = (kind) => {
229
+ if (typeof window === "undefined" || !window.__DINOU_INLINE_RSC__) {
230
+ return null;
231
+ }
232
+ const consumedFlag = `__DINOU_RSC_${kind}_CONSUMED__`;
233
+ if (window[consumedFlag]) {
234
+ return null;
235
+ }
236
+ window[consumedFlag] = true;
237
+
238
+ const arrName = `__DINOU_RSC_${kind}__`;
239
+ const doneName = `__DINOU_RSC_${kind}_DONE__`;
240
+ const pushFnName = `__DINOU_RSC_${kind}_PUSH__`;
241
+ const closeFnName = `__DINOU_RSC_${kind}_CLOSE__`;
242
+
243
+ const encoder = new TextEncoder();
244
+ const stream = new ReadableStream({
245
+ start(controller) {
246
+ let closed = false;
247
+ const existing = window[arrName];
248
+ if (Array.isArray(existing)) {
249
+ for (const chunk of existing) {
250
+ if (chunk) controller.enqueue(encoder.encode(chunk));
251
+ }
252
+ existing.length = 0;
253
+ }
254
+ if (window[doneName]) {
255
+ closed = true;
256
+ controller.close();
257
+ return;
258
+ }
259
+ window[pushFnName] = (chunk) => {
260
+ if (closed || !chunk) return;
261
+ try {
262
+ controller.enqueue(encoder.encode(chunk));
263
+ } catch (e) {}
264
+ };
265
+ window[closeFnName] = () => {
266
+ if (closed) return;
267
+ closed = true;
268
+ try {
269
+ controller.close();
270
+ } catch (e) {}
271
+ };
272
+ if (document.readyState === "complete" && !window[doneName]) {
273
+ setTimeout(() => {
274
+ if (!closed) {
275
+ closed = true;
276
+ try {
277
+ controller.close();
278
+ } catch (e) {}
279
+ }
280
+ }, 0);
281
+ }
282
+ },
283
+ });
284
+
285
+ return new Response(stream, {
286
+ status: 200,
287
+ headers: { "Content-Type": "text/x-component" },
288
+ });
289
+ };
290
+
291
+ const isStaticExportMode = () =>
292
+ typeof window !== "undefined" && Boolean(window.__DINOU_STATIC_EXPORT__);
293
+
294
+ const isStaticExportUnloading = () =>
295
+ typeof window !== "undefined" && Boolean(window.__DINOU_STATIC_EXPORT_UNLOADING__);
296
+
297
+ // Static-export .rsc payloads are pre-rendered static files (not streaming SSR).
298
+ // Buffer the body into an in-memory ArrayBuffer before handing a Response to
299
+ // createFromFetch so that triggering window.location.replace() on a non-RSC
300
+ // fallback cannot abort an in-flight network ReadableStream (e.g. Firefox's
301
+ // "Error in input stream") inside React Flight's stream reader.
302
+ const bufferStaticExportResponse = (res) => {
303
+ if (isStaticExportUnloading()) {
304
+ return new Promise(() => {});
305
+ }
306
+ return res.arrayBuffer().then(
307
+ (buf) => {
308
+ if (isStaticExportUnloading()) {
309
+ return new Promise(() => {});
310
+ }
311
+ return new Response(buf, {
312
+ status: res.status,
313
+ statusText: res.statusText,
314
+ headers: {
315
+ "Content-Type": res.headers.get("content-type") || "text/x-component",
316
+ },
317
+ });
318
+ },
319
+ (err) => {
320
+ if (isStaticExportUnloading()) {
321
+ return new Promise(() => {});
322
+ }
323
+ throw err;
324
+ }
325
+ );
326
+ };
327
+
328
+ const buildStaticExportRscUrl = (rawRouteOrKey, fileName) => {
329
+ const withoutHash = String(rawRouteOrKey || "/").split("#")[0];
330
+ const qIdx = withoutHash.indexOf("?");
331
+ const rawPathname = qIdx === -1 ? withoutHash : withoutHash.slice(0, qIdx);
332
+ const existingQuery = qIdx === -1 ? "" : withoutHash.slice(qIdx + 1);
333
+ const cleanPathname = rawPathname.replace(/\/+$/, "");
334
+ const baseRscPath = cleanPathname ? `${cleanPathname}/${fileName}` : `/${fileName}`;
335
+ return existingQuery ? `${baseRscPath}?${existingQuery}` : baseRscPath;
336
+ };
337
+
338
+ const executeRscRedirect = (redirectUrl) => {
339
+ if (!redirectUrl || typeof window === "undefined") return;
340
+ if (/^https?:\/\//i.test(redirectUrl) || !window.__DINOU_ROUTER_NAVIGATE__) {
341
+ window.location.href = redirectUrl;
342
+ return;
343
+ }
344
+ if (getCurrentRoute() !== redirectUrl) {
345
+ window.__DINOU_ROUTER_NAVIGATE__(redirectUrl, { replace: true });
346
+ }
347
+ };
348
+
140
349
  const getPagePayload = (route, isPrefetch = false, version = 0) => {
141
- const url = route.split("::")[0];
350
+ const url = route.split("::")[0].split("#")[0] || "/";
142
351
  if (pageCache.has(url)) {
143
352
  return pageCache.get(url);
144
353
  }
145
354
 
355
+ const staticExport = isStaticExportMode();
356
+ if (staticExport && isStaticExportUnloading()) {
357
+ const pendingPromise = createFromFetch(new Promise(() => {}), {
358
+ callServer: async (id, args) => {
359
+ const proxy = createServerFunctionProxy(id);
360
+ return proxy(...args);
361
+ },
362
+ });
363
+ pendingPromise.catch(() => {});
364
+ pageCache.set(url, pendingPromise);
365
+ return pendingPromise;
366
+ }
146
367
  let payloadUrl;
147
- if (window.__DINOU_USE_OLD_RSC__ || window.__DINOU_USE_STATIC__) {
368
+ if (staticExport) {
369
+ payloadUrl = buildStaticExportRscUrl(url, "page.rsc");
370
+ } else if (window.__DINOU_USE_OLD_RSC__ || window.__DINOU_USE_STATIC__) {
148
371
  payloadUrl = window.__DINOU_USE_OLD_RSC__
149
372
  ? window.__DINOU_USE_STATIC__
150
373
  ? "/____rsc_page_old_static____" + url
@@ -160,7 +383,8 @@ const getPagePayload = (route, isPrefetch = false, version = 0) => {
160
383
  !isPrefetch &&
161
384
  typeof document !== "undefined" &&
162
385
  (!document.body || document.body.getAttribute("data-hydrated") !== "true");
163
- const buildId = isInitialHydration ? window.__DINOU_BUILD_ID__ : undefined;
386
+ const buildId =
387
+ staticExport || isInitialHydration ? window.__DINOU_BUILD_ID__ : undefined;
164
388
  if (buildId && !version) {
165
389
  payloadUrl += (payloadUrl.includes("?") ? "&" : "?") + "____build_id____=" + buildId;
166
390
  }
@@ -168,22 +392,52 @@ const getPagePayload = (route, isPrefetch = false, version = 0) => {
168
392
  payloadUrl += (payloadUrl.includes("?") ? "&" : "?") + "____v____=" + version;
169
393
  }
170
394
 
171
- const promise = createFromFetch(
172
- fetch(payloadUrl).then((res) => {
173
- if (res.headers.has("x-rsc-redirect")) {
174
- const redirectUrl = res.headers.get("x-rsc-redirect");
175
- pageCache.delete(url);
176
- if (!isPrefetch) {
177
- if (window.__DINOU_ROUTER_NAVIGATE__) {
178
- window.__DINOU_ROUTER_NAVIGATE__(redirectUrl, { replace: true });
395
+ const inlineRes = isInitialHydration && !version ? consumeInlineRscResponse("P") : null;
396
+ const fetchPromise = inlineRes
397
+ ? Promise.resolve(inlineRes)
398
+ : fetch(payloadUrl, {
399
+ cache: staticExport && !version ? "default" : "no-store",
400
+ }).then((res) => {
401
+ if (res.headers.has("x-rsc-redirect")) {
402
+ const redirectUrl = res.headers.get("x-rsc-redirect");
403
+ const isCurrentTarget =
404
+ typeof window !== "undefined" &&
405
+ getCurrentRoute() === url.split("#")[0];
406
+ pageCache.delete(url);
407
+ if (isCurrentTarget && redirectUrl) {
408
+ executeRscRedirect(redirectUrl);
409
+ }
410
+ return new Promise(() => {});
411
+ }
412
+ if (isStaticExportUnloading()) {
413
+ return new Promise(() => {});
414
+ }
415
+ if (
416
+ staticExport &&
417
+ (!res.ok ||
418
+ (res.headers.get("content-type") || "").toLowerCase().includes("text/html"))
419
+ ) {
420
+ if (!isPrefetch && !isInitialHydration) {
421
+ window.__DINOU_STATIC_EXPORT_UNLOADING__ = true;
422
+ window.location.replace(url);
179
423
  } else {
180
- window.location.href = redirectUrl;
424
+ pageCache.delete(url);
181
425
  }
426
+ return new Promise(() => {});
182
427
  }
183
- return new Promise(() => {});
184
- }
185
- return res;
186
- }),
428
+ if (staticExport) {
429
+ return bufferStaticExportResponse(res);
430
+ }
431
+ return res;
432
+ }, (err) => {
433
+ if (isStaticExportUnloading()) {
434
+ return new Promise(() => {});
435
+ }
436
+ throw err;
437
+ });
438
+
439
+ const promise = createFromFetch(
440
+ fetchPromise,
187
441
  {
188
442
  callServer: async (id, args) => {
189
443
  const proxy = createServerFunctionProxy(id);
@@ -199,20 +453,34 @@ const getPagePayload = (route, isPrefetch = false, version = 0) => {
199
453
 
200
454
  const getLayoutPayload = (layoutKey, searchPart = "", version = 0) => {
201
455
  if (!layoutKey) return null;
202
- const cacheKey = `${layoutKey}${searchPart}`;
456
+ const staticExport = isStaticExportMode();
457
+ const cacheKey = staticExport ? layoutKey : `${layoutKey}${searchPart}`;
203
458
  if (layoutCache.has(cacheKey)) {
204
459
  return layoutCache.get(cacheKey);
205
460
  }
461
+ if (staticExport && isStaticExportUnloading()) {
462
+ const pendingPromise = createFromFetch(new Promise(() => {}), {
463
+ callServer: async (id, args) => {
464
+ const proxy = createServerFunctionProxy(id);
465
+ return proxy(...args);
466
+ },
467
+ });
468
+ pendingPromise.catch(() => {});
469
+ layoutCache.set(cacheKey, pendingPromise);
470
+ return pendingPromise;
471
+ }
206
472
 
207
473
  const isInitialHydration =
208
474
  typeof document !== "undefined" &&
209
475
  (!document.body || document.body.getAttribute("data-hydrated") !== "true");
210
- const buildId = isInitialHydration ? window.__DINOU_BUILD_ID__ : undefined;
476
+ const buildId =
477
+ staticExport || isInitialHydration ? window.__DINOU_BUILD_ID__ : undefined;
211
478
  const cleanKey = layoutKey === "/" ? "" : layoutKey;
212
- let layoutUrl =
213
- (window.__DINOU_USE_STATIC__
214
- ? "/____rsc_layout_static____"
215
- : "/____rsc_layout____") + cleanKey + searchPart;
479
+ let layoutUrl = staticExport
480
+ ? buildStaticExportRscUrl((cleanKey || "/") + searchPart, "layout.rsc")
481
+ : (window.__DINOU_USE_STATIC__
482
+ ? "/____rsc_layout_static____"
483
+ : "/____rsc_layout____") + cleanKey + searchPart;
216
484
 
217
485
  if (buildId && !version) {
218
486
  layoutUrl += (layoutUrl.includes("?") ? "&" : "?") + "____build_id____=" + buildId;
@@ -222,15 +490,54 @@ const getLayoutPayload = (layoutKey, searchPart = "", version = 0) => {
222
490
  layoutUrl += (layoutUrl.includes("?") ? "&" : "?") + "____v____=" + version;
223
491
  }
224
492
 
493
+ const inlineRes = isInitialHydration && !version ? consumeInlineRscResponse("L") : null;
494
+ const fetchPromise = inlineRes
495
+ ? Promise.resolve(inlineRes)
496
+ : fetch(layoutUrl, {
497
+ cache: staticExport && !version ? "default" : "no-store",
498
+ }).then(
499
+ (res) => {
500
+ if (res.headers.has("x-rsc-redirect")) {
501
+ const redirectUrl = res.headers.get("x-rsc-redirect");
502
+ const isCurrentLayout =
503
+ typeof window !== "undefined" &&
504
+ getLayoutKey(window.location.pathname) === layoutKey;
505
+ layoutCache.delete(cacheKey);
506
+ if (isCurrentLayout && redirectUrl) {
507
+ executeRscRedirect(redirectUrl);
508
+ }
509
+ return new Promise(() => {});
510
+ }
511
+ if (isStaticExportUnloading()) {
512
+ return new Promise(() => {});
513
+ }
514
+ if (
515
+ staticExport &&
516
+ (!res.ok ||
517
+ (res.headers.get("content-type") || "").toLowerCase().includes("text/html"))
518
+ ) {
519
+ return new Promise(() => {});
520
+ }
521
+ if (staticExport) {
522
+ return bufferStaticExportResponse(res);
523
+ }
524
+ if (!res.ok) {
525
+ console.warn(
526
+ `[Dinou Router] Layout ${layoutKey} fetch returned status ${res.status}`
527
+ );
528
+ }
529
+ return res;
530
+ },
531
+ (err) => {
532
+ if (isStaticExportUnloading()) {
533
+ return new Promise(() => {});
534
+ }
535
+ throw err;
536
+ }
537
+ );
538
+
225
539
  const promise = createFromFetch(
226
- fetch(layoutUrl).then((res) => {
227
- if (!res.ok) {
228
- console.warn(
229
- `[Dinou Router] Layout ${layoutKey} fetch returned status ${res.status}`
230
- );
231
- }
232
- return res;
233
- }),
540
+ fetchPromise,
234
541
  {
235
542
  callServer: async (id, args) => {
236
543
  const proxy = createServerFunctionProxy(id);
@@ -245,6 +552,9 @@ const getLayoutPayload = (layoutKey, searchPart = "", version = 0) => {
245
552
  };
246
553
 
247
554
  const getErrorRSCPayload = (route, error) => {
555
+ if (isStaticExportMode() || isStaticExportUnloading()) {
556
+ return null;
557
+ }
248
558
  const url = route.split("::")[0];
249
559
  const cacheKey = `error::${url}::${error.message || String(error)}`;
250
560
  if (pageCache.has(cacheKey)) {
@@ -285,6 +595,7 @@ const getErrorRSCPayload = (route, error) => {
285
595
  }
286
596
  }
287
597
  );
598
+ promise.catch(() => {});
288
599
  pageCache.set(cacheKey, promise);
289
600
  return promise;
290
601
  };
@@ -313,6 +624,7 @@ const fetchSlotRSC = (slotId, options = {}) => {
313
624
 
314
625
  export const refreshSlot = (slotId, options) => {
315
626
  if (typeof window !== "undefined") {
627
+ flushPendingSsrStreams();
316
628
  const promises = [];
317
629
  window.dispatchEvent(
318
630
  new CustomEvent("dinou:refresh-slot", {
@@ -341,6 +653,7 @@ class ErrorBoundary extends Component {
341
653
  }
342
654
 
343
655
  componentDidCatch(error, errorInfo) {
656
+ if (isStaticExportUnloading()) return;
344
657
  console.error("[Dinou] ErrorBoundary caught error:", error, errorInfo);
345
658
  if (this.props.onError) {
346
659
  this.props.onError(error);
@@ -355,6 +668,9 @@ class ErrorBoundary extends Component {
355
668
 
356
669
  render() {
357
670
  if (this.state.hasError) {
671
+ if (isStaticExportUnloading()) {
672
+ return null;
673
+ }
358
674
  if (this.props.fallback) {
359
675
  return this.props.fallback(this.state.error);
360
676
  }
@@ -476,6 +792,15 @@ function Router() {
476
792
  }
477
793
  const finalPath = resolveUrl(href, window.location.pathname);
478
794
 
795
+ if (isExternalUrl(finalPath)) {
796
+ if (options.replace) {
797
+ window.location.replace(finalPath);
798
+ } else {
799
+ window.location.assign(finalPath);
800
+ }
801
+ return;
802
+ }
803
+
479
804
  // 🛡️ NAVIGATE PROTECTION: Hash Detection
480
805
  if (isHashChangeOnly(finalPath)) {
481
806
  if (options.replace) {
@@ -494,8 +819,10 @@ function Router() {
494
819
  return; // CRITICAL STOP
495
820
  }
496
821
 
822
+ const routeWithoutHash = finalPath.split("#")[0] || "/";
823
+
497
824
  if (options.fresh) {
498
- pageCache.delete(finalPath);
825
+ pageCache.delete(routeWithoutHash);
499
826
  }
500
827
 
501
828
  // Normal RSC Navigation
@@ -509,9 +836,13 @@ function Router() {
509
836
  window.history.pushState(null, "", finalPath);
510
837
  }
511
838
 
839
+ flushPendingSsrStreams();
512
840
  startTransition(() => {
513
841
  setIsPopState(false);
514
- setRoute(finalPath);
842
+ setRoute(routeWithoutHash);
843
+ if (options.fresh) {
844
+ setVersion((v) => v + 1);
845
+ }
515
846
  setNavError(null);
516
847
  setNavCount((c) => c + 1);
517
848
  });
@@ -535,6 +866,7 @@ function Router() {
535
866
  }
536
867
  }
537
868
 
869
+ flushPendingSsrStreams();
538
870
  startTransition(() => {
539
871
  setVersion((v) => v + 1);
540
872
  if (shouldRefreshLayout) {
@@ -550,17 +882,19 @@ function Router() {
550
882
  window.__DINOU_PREFETCH__ = (url) => {
551
883
  // 🛡️ PREFETCH PROTECTION: If it's a local hash, do nothing
552
884
  if (isHashChangeOnly(url)) return;
553
- const lKey = getLayoutKey(url);
885
+ const cleanUrl = String(url || "/").split("#")[0] || "/";
886
+ const lKey = getLayoutKey(cleanUrl);
554
887
  if (lKey && !layoutCache.has(lKey)) {
555
888
  getLayoutPayload(lKey);
556
889
  }
557
- getPagePayload(url, true);
890
+ getPagePayload(cleanUrl, true);
558
891
  };
559
892
 
560
893
  window.__DINOU_ROUTER_NAVIGATE__ = navigate;
561
894
  window.__DINOU_ROUTER_REFRESH__ = refresh;
562
895
 
563
896
  // Hydration
897
+ flushPendingSsrStreams();
564
898
  document.body.setAttribute("data-hydrated", "true");
565
899
 
566
900
  return () => {
@@ -585,7 +919,9 @@ function Router() {
585
919
  const anchor = e.target.closest("a");
586
920
  if (
587
921
  !anchor ||
588
- anchor.target ||
922
+ (anchor.target && anchor.target !== "_self") ||
923
+ anchor.hasAttribute("download") ||
924
+ e.button !== 0 ||
589
925
  e.metaKey ||
590
926
  e.ctrlKey ||
591
927
  e.shiftKey ||
@@ -616,6 +952,7 @@ function Router() {
616
952
  window.__DINOU_ACTIVE_LAYOUT__ = null;
617
953
  }
618
954
  const target = getCurrentRoute();
955
+ flushPendingSsrStreams();
619
956
  startTransition(() => {
620
957
  setIsPopState(true);
621
958
  setRoute(target);
@@ -730,6 +1067,7 @@ function Router() {
730
1067
  }, [route, version, navError]);
731
1068
 
732
1069
  useLayoutEffect(() => {
1070
+ pruneOrphanedSsrStreams();
733
1071
  if (
734
1072
  typeof document !== "undefined" &&
735
1073
  document.body &&
@@ -769,7 +1107,7 @@ function Router() {
769
1107
  <RouterContext.Provider value={contextValue}>
770
1108
  <ErrorBoundary
771
1109
  resetKey={`${route}::${navCount}`}
772
- onError={setNavError}
1110
+ onError={isStaticExportMode() ? undefined : setNavError}
773
1111
  >
774
1112
  <DinouPageContext.Provider value={slotContextValue}>
775
1113
  {navError
@@ -792,6 +1130,9 @@ const app = useStrictMode
792
1130
  : routerElement;
793
1131
 
794
1132
  const onRecoverableError = (error) => {
1133
+ if (isStaticExportUnloading()) {
1134
+ return;
1135
+ }
795
1136
  // 🛡️ Filter benign ViewTransition aborts when document is hidden (e.g. background tab or HMR while in IDE)
796
1137
  if (
797
1138
  error?.name === "InvalidStateError" &&
@@ -810,6 +1151,24 @@ const onRecoverableError = (error) => {
810
1151
  }
811
1152
  };
812
1153
 
1154
+ const onUncaughtError = (error) => {
1155
+ if (isStaticExportUnloading()) {
1156
+ return;
1157
+ }
1158
+ if (typeof reportError === "function") {
1159
+ reportError(error);
1160
+ } else {
1161
+ console.error(error);
1162
+ }
1163
+ };
1164
+
1165
+ const onCaughtError = (error) => {
1166
+ if (isStaticExportUnloading()) {
1167
+ return;
1168
+ }
1169
+ console.error(error);
1170
+ };
1171
+
813
1172
  // If the server rendered a fatal layout error during SSR (meaning there is no layout DOM to hydrate),
814
1173
  // do NOT attempt to hydrate the application over it.
815
1174
  const hasInitialServerError =
@@ -818,7 +1177,11 @@ const isLayoutError =
818
1177
  hasInitialServerError && window.__DINOU_ERROR_SEGMENT__ !== "page";
819
1178
 
820
1179
  if (!isLayoutError) {
821
- hydrateRoot(document, app, { onRecoverableError });
1180
+ hydrateRoot(document, app, {
1181
+ onRecoverableError,
1182
+ onUncaughtError,
1183
+ onCaughtError,
1184
+ });
822
1185
  } else {
823
1186
  console.warn(
824
1187
  "[Dinou] Initial layout server error detected:",
@@ -1,8 +1,11 @@
1
1
  // dinou/core/config.js
2
2
  // Type helper for defining Dinou configuration and plugins
3
+ import { getContext } from "./request-context.js";
4
+ import { noDynamic } from "./no-dynamic.js";
3
5
 
4
6
  export function defineConfig(config) {
5
7
  return config;
6
8
  }
7
9
 
10
+ export { getContext, noDynamic };
8
11
  export default defineConfig;