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
@@ -25,7 +25,141 @@ export function isExternalUrl(href) {
25
25
  return false;
26
26
  }
27
27
 
28
- export function resolveUrl(href, currentPathname) {
28
+ /**
29
+ * Interpolates dynamic route segments (`[param]`, `[...param]`, `[[param]]`, `[[...param]]`)
30
+ * using the provided `params` dictionary while preserving query strings and hashes.
31
+ * Fast-paths static and already-interpolated URLs with zero allocations.
32
+ */
33
+ export function interpolateRouteParams(href, params) {
34
+ if (!href || typeof href !== "string") {
35
+ return "";
36
+ }
37
+
38
+ if (!params && !href.includes("[")) {
39
+ return href;
40
+ }
41
+
42
+ if (isExternalUrl(href)) {
43
+ return href;
44
+ }
45
+
46
+ const qIdx = href.indexOf("?");
47
+ const hIdx = href.indexOf("#");
48
+ let splitIdx = -1;
49
+ if (qIdx !== -1 && hIdx !== -1) splitIdx = Math.min(qIdx, hIdx);
50
+ else if (qIdx !== -1) splitIdx = qIdx;
51
+ else if (hIdx !== -1) splitIdx = hIdx;
52
+
53
+ const pathnamePart = splitIdx === -1 ? href : href.slice(0, splitIdx);
54
+ const suffix = splitIdx === -1 ? "" : href.slice(splitIdx);
55
+
56
+ if (!pathnamePart || !pathnamePart.includes("[")) {
57
+ return href;
58
+ }
59
+
60
+ const isDev =
61
+ typeof process !== "undefined" &&
62
+ process.env &&
63
+ process.env.NODE_ENV !== "production";
64
+
65
+ const hasLeadingSlash = pathnamePart.startsWith("/");
66
+ const rawSegments = (
67
+ hasLeadingSlash ? pathnamePart.slice(1) : pathnamePart
68
+ ).split("/");
69
+ const outSegments = [];
70
+
71
+ for (const seg of rawSegments) {
72
+ if (seg === "") continue;
73
+
74
+ if (seg.startsWith("[[...") && seg.endsWith("]]")) {
75
+ const key = seg.slice(5, -2);
76
+ const val = params ? params[key] : undefined;
77
+ if (val == null) continue;
78
+ if (Array.isArray(val)) {
79
+ for (const item of val) {
80
+ if (item != null && String(item) !== "") {
81
+ outSegments.push(encodeURIComponent(String(item)));
82
+ }
83
+ }
84
+ } else if (String(val) !== "") {
85
+ outSegments.push(encodeURIComponent(String(val)));
86
+ }
87
+ } else if (seg.startsWith("[[") && seg.endsWith("]]")) {
88
+ const key = seg.slice(2, -2);
89
+ const val = params ? params[key] : undefined;
90
+ if (val == null || String(val) === "") continue;
91
+ outSegments.push(encodeURIComponent(String(val)));
92
+ } else if (seg.startsWith("[...") && seg.endsWith("]")) {
93
+ const key = seg.slice(4, -1);
94
+ const val = params ? params[key] : undefined;
95
+ if (Array.isArray(val) && val.length > 0) {
96
+ for (const item of val) {
97
+ outSegments.push(encodeURIComponent(String(item)));
98
+ }
99
+ } else if (val != null && !Array.isArray(val) && String(val) !== "") {
100
+ outSegments.push(encodeURIComponent(String(val)));
101
+ } else {
102
+ if (isDev) {
103
+ console.error(
104
+ `[Dinou] Missing required catch-all route parameter "${key}" for route pattern "${href}".`
105
+ );
106
+ }
107
+ outSegments.push(seg);
108
+ }
109
+ } else if (seg.startsWith("[") && seg.endsWith("]")) {
110
+ const key = seg.slice(1, -1);
111
+ const val = params ? params[key] : undefined;
112
+ if (val != null && String(val) !== "") {
113
+ outSegments.push(encodeURIComponent(String(val)));
114
+ } else {
115
+ if (isDev) {
116
+ console.error(
117
+ `[Dinou] Missing required route parameter "${key}" for route pattern "${href}".`
118
+ );
119
+ }
120
+ outSegments.push(seg);
121
+ }
122
+ } else {
123
+ outSegments.push(seg);
124
+ }
125
+ }
126
+
127
+ const interpolatedPath = hasLeadingSlash
128
+ ? "/" + outSegments.join("/")
129
+ : outSegments.join("/");
130
+
131
+ return interpolatedPath + suffix;
132
+ }
133
+
134
+ export function resolveBasePathname(from, currentPathname) {
135
+ if (!from || typeof from !== "string" || !currentPathname) {
136
+ return currentPathname || "/";
137
+ }
138
+ const cleanFrom = from.startsWith("/") ? from : "/" + from;
139
+ if (cleanFrom === "/") {
140
+ return "/";
141
+ }
142
+ const fromSegs = cleanFrom.slice(1).split("/").filter(Boolean);
143
+ if (fromSegs.some((s) => s.startsWith("[...") || s.startsWith("[["))) {
144
+ return currentPathname;
145
+ }
146
+ const pathSegs = currentPathname
147
+ .split("?")[0]
148
+ .split("#")[0]
149
+ .split("/")
150
+ .filter(Boolean);
151
+ if (pathSegs.length < fromSegs.length) {
152
+ return currentPathname;
153
+ }
154
+ for (let i = 0; i < fromSegs.length; i++) {
155
+ const fSeg = fromSegs[i];
156
+ if (fSeg.startsWith("[") && fSeg.endsWith("]")) continue;
157
+ if (fSeg !== pathSegs[i]) return currentPathname;
158
+ }
159
+ return "/" + pathSegs.slice(0, fromSegs.length).join("/");
160
+ }
161
+
162
+ export function resolveUrl(href, currentPathname, from) {
29
163
  if (!href) {
30
164
  return "";
31
165
  }
@@ -41,8 +175,12 @@ export function resolveUrl(href, currentPathname) {
41
175
  return normalize(url.pathname + url.search + url.hash);
42
176
  }
43
177
 
44
- let base = currentPathname;
45
- if (!base.endsWith("/")) base += "/";
178
+ const isQueryOrHashOnly = href.startsWith("?") || href.startsWith("#");
179
+ let base =
180
+ (!isQueryOrHashOnly && from
181
+ ? resolveBasePathname(from, currentPathname)
182
+ : currentPathname) || "/";
183
+ if (!isQueryOrHashOnly && !base.endsWith("/")) base += "/";
46
184
 
47
185
  const resolved = new URL(href, origin + base);
48
186
  return normalize(resolved.pathname + resolved.search + resolved.hash);
@@ -1,6 +1,7 @@
1
1
  // dinou/core/navigation.js
2
2
  "use client";
3
3
  import React from "react";
4
+ import { interpolateRouteParams, resolveUrl } from "./navigation-utils.js";
4
5
 
5
6
  // Defensive mocks
6
7
  const createContext =
@@ -10,6 +11,14 @@ const createContext =
10
11
  _currentValue: defaultValue,
11
12
  }));
12
13
  const useContext = React.useContext || (() => null);
14
+ const useState =
15
+ React.useState ||
16
+ ((init) => [typeof init === "function" ? init() : init, () => {}]);
17
+ const useEffect = React.useEffect || (() => {});
18
+ const useMemo = React.useMemo || ((fn) => fn());
19
+ const useSyncExternalStore =
20
+ React.useSyncExternalStore || ((_sub, getSnap) => getSnap());
21
+ const emptySubscribe = () => () => {};
13
22
 
14
23
  // 🔄 CHANGE: Now default value is a compatible object
15
24
  export const RouterContext = createContext({
@@ -54,50 +63,67 @@ export function useNavigationLoading() {
54
63
  export function useRouter() {
55
64
  const context = useContext(RouterContext);
56
65
 
57
- // Guards for SSR (optional, but good practice)
58
- if (!context) {
59
- // On the server we return empty functions to not break the rendering
66
+ return useMemo(() => {
67
+ // Guards for SSR (optional, but good practice)
68
+ if (!context) {
69
+ // On the server we return empty functions to not break the rendering
70
+ return {
71
+ push: () => {},
72
+ replace: () => {},
73
+ back: () => {},
74
+ forward: () => {},
75
+ refresh: () => {},
76
+ refreshSlot: () => Promise.resolve(),
77
+ };
78
+ }
79
+
60
80
  return {
61
- push: () => { },
62
- replace: () => { },
63
- back: () => { },
64
- forward: () => { },
65
- refresh: (options) => { },
66
- refreshSlot: (slotId, options) => Promise.resolve(),
67
- };
68
- }
81
+ push: (href, options) => {
82
+ const { params, from, ...restOptions } = options || {};
83
+ const interpolated = interpolateRouteParams(href, params);
84
+ const target =
85
+ from && typeof window !== "undefined"
86
+ ? resolveUrl(interpolated, window.location.pathname, from)
87
+ : interpolated;
88
+ return context.navigate(target, restOptions);
89
+ },
90
+ replace: (href, options) => {
91
+ const { params, from, ...restOptions } = options || {};
92
+ const interpolated = interpolateRouteParams(href, params);
93
+ const target =
94
+ from && typeof window !== "undefined"
95
+ ? resolveUrl(interpolated, window.location.pathname, from)
96
+ : interpolated;
97
+ return context.navigate(target, { replace: true, ...restOptions });
98
+ },
99
+
100
+ /**
101
+ * Navigate back in the browser's history.
102
+ * Equivalent to clicking the browser's Back button.
103
+ */
104
+ back: () => context.back?.(),
69
105
 
70
- return {
71
- push: (href, options) => context.navigate(href, options),
72
- replace: (href, options) =>
73
- context.navigate(href, { replace: true, ...options }),
74
-
75
- /**
76
- * Navigate back in the browser's history.
77
- * Equivalent to clicking the browser's Back button.
78
- */
79
- back: () => context.back(),
80
-
81
- /**
82
- * Navigate forward in the browser's history.
83
- */
84
- forward: () => context.forward(),
85
-
86
- /**
87
- * Refresh the current route.
88
- * Makes a new request to the server for the current URL, clearing the cache,
89
- * and re-renders the server component without a full browser reload.
90
- * Pass `{ layout: true }` to also invalidate and re-render the layout.
91
- */
92
- refresh: (options) => context.refresh(options),
93
-
94
- /**
95
- * Refresh a specific DinouCacheSlot without re-rendering the rest of the page.
96
- * @param {string} slotId The ID or tag of the slot to refresh.
97
- * @param {object} [options] Optional configuration ({ fresh?: boolean }).
98
- */
99
- refreshSlot: (slotId, options) => refreshSlot(slotId, options),
100
- };
106
+ /**
107
+ * Navigate forward in the browser's history.
108
+ */
109
+ forward: () => context.forward?.(),
110
+
111
+ /**
112
+ * Refresh the current route.
113
+ * Makes a new request to the server for the current URL, clearing the cache,
114
+ * and re-renders the server component without a full browser reload.
115
+ * Pass `{ layout: true }` to also invalidate and re-render the layout.
116
+ */
117
+ refresh: (options) => context.refresh?.(options),
118
+
119
+ /**
120
+ * Refresh a specific DinouCacheSlot without re-rendering the rest of the page.
121
+ * @param {string} slotId The ID or tag of the slot to refresh.
122
+ * @param {object} [options] Optional configuration ({ fresh?: boolean }).
123
+ */
124
+ refreshSlot: (slotId, options) => refreshSlot(slotId, options),
125
+ };
126
+ }, [context]);
101
127
  }
102
128
 
103
129
  export function refreshSlot(slotId, options) {
@@ -117,6 +143,21 @@ export function refreshSlot(slotId, options) {
117
143
  }
118
144
 
119
145
  const DINOU_CONTEXT_KEY = Symbol.for("dinou.request.context.storage");
146
+ const BAILOUT_RAW_TARGET = Symbol.for("dinou.bailout.raw");
147
+
148
+ function queryObjectToURLSearchParams(query) {
149
+ const params = new URLSearchParams();
150
+ Object.entries(query).forEach(([key, val]) => {
151
+ if (Array.isArray(val)) {
152
+ val.forEach((v) => {
153
+ if (v !== undefined && v !== null) params.append(key, String(v));
154
+ });
155
+ } else if (val !== undefined && val !== null) {
156
+ params.append(key, String(val));
157
+ }
158
+ });
159
+ return params;
160
+ }
120
161
 
121
162
  export function usePathname() {
122
163
  // 🟢 1. SERVER LOGIC (SSR)
@@ -153,21 +194,64 @@ export function useSearchParams() {
153
194
  if (typeof window === "undefined") {
154
195
  try {
155
196
  const storage = globalThis[DINOU_CONTEXT_KEY];
156
- const ctx = storage && typeof storage.getStore === "function" ? storage.getStore() : null;
197
+ const ctx =
198
+ (storage && typeof storage.getStore === "function"
199
+ ? storage.getStore()
200
+ : null) || globalThis[Symbol.for("dinou.request.context.current")];
201
+ const clientH =
202
+ React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE?.H;
203
+ const isClientSsrRender =
204
+ typeof React.useState === "function" &&
205
+ Boolean(clientH) &&
206
+ !clientH._dinouIsServerHooksDispatcher;
207
+ if (isClientSsrRender) {
208
+ if (!ctx || ctx._isPprRuntimeResume || ctx._isStaticHtmlRender) {
209
+ return new URLSearchParams();
210
+ }
211
+ const rawQuery =
212
+ ctx.req && ctx.req.query
213
+ ? ctx.req.query[BAILOUT_RAW_TARGET] || ctx.req.query
214
+ : null;
215
+ if (rawQuery) {
216
+ return queryObjectToURLSearchParams(rawQuery);
217
+ }
218
+ return new URLSearchParams();
219
+ }
157
220
  if (ctx && ctx.req && ctx.req.query) {
158
- const params = new URLSearchParams();
159
- Object.entries(ctx.req.query).forEach(([key, val]) => {
160
- if (Array.isArray(val)) val.forEach((v) => params.append(key, v));
161
- else if (val) params.append(key, val);
162
- });
163
- return params;
221
+ return queryObjectToURLSearchParams(ctx.req.query);
164
222
  }
165
- } catch (e) { }
223
+ } catch (e) {
224
+ if (
225
+ e &&
226
+ (e.$$typeof === Symbol.for("dinou.ppr.postpone") ||
227
+ e.$$typeof === Symbol.for("react.postpone") ||
228
+ e.$$typeof === Symbol.for("dinou.ppr.skipStatic"))
229
+ ) {
230
+ throw e;
231
+ }
232
+ }
166
233
  return new URLSearchParams();
167
234
  }
168
235
 
169
236
  // 🔵 2. CLIENT LOGIC
170
237
  const context = useContext(RouterContext);
238
+ const isReactHydrating = useSyncExternalStore(
239
+ emptySubscribe,
240
+ () => false,
241
+ () => true
242
+ );
243
+ const isStaticHydrating =
244
+ isReactHydrating &&
245
+ typeof window !== "undefined" &&
246
+ Boolean(
247
+ window.__DINOU_USE_STATIC__ ||
248
+ window.__DINOU_PPR_RESUME__ ||
249
+ window.__DINOU_STATIC_EXPORT__
250
+ );
251
+
252
+ if (isStaticHydrating) {
253
+ return new URLSearchParams();
254
+ }
171
255
 
172
256
  // ⚠️ CRITICAL CHANGE: We extract .url
173
257
  const fullRoute = typeof context === "string" ? context : context?.url;
@@ -0,0 +1,165 @@
1
+ // dinou/core/node-middleware-runner.js
2
+ // Shared Node.js configureServer hook runner and Connect/Express-style
3
+ // (req, res, next) middleware executor for dev and production servers.
4
+
5
+ /**
6
+ * Executes a single Node.js HTTP middleware `(req, res, next)`.
7
+ * Supports:
8
+ * - Synchronous `next()` middlewares
9
+ * - Async Promise-returning middlewares (`async (req, res, next) => { ... }`)
10
+ * - Callback-async Connect/Express middlewares (`cors`, `helmet`, `compression`, etc.)
11
+ * - `next(err)` error propagation
12
+ * - Direct response termination (`res.end()`, `res.writeHead()`)
13
+ * - External `server.on("request")` hijacking (e.g. Socket.IO `/socket.io/` polling
14
+ * where `mw` returns synchronously without calling `next()` and Socket.IO ends `res`).
15
+ *
16
+ * @param {Function} mw
17
+ * @param {import("node:http").IncomingMessage} req
18
+ * @param {import("node:http").ServerResponse} res
19
+ * @returns {Promise<boolean>} `true` if Dinou should continue handling the request, `false` if handled/short-circuited
20
+ */
21
+ async function runSingleNodeMiddleware(mw, req, res) {
22
+ let nextCalled = false;
23
+ let nextError = null;
24
+ let resolveWait = null;
25
+
26
+ const next = (err) => {
27
+ if (nextCalled) return;
28
+ nextCalled = true;
29
+ if (err !== undefined && err !== null) {
30
+ nextError = err instanceof Error ? err : new Error(String(err));
31
+ }
32
+ if (resolveWait) {
33
+ const fn = resolveWait;
34
+ resolveWait = null;
35
+ fn();
36
+ }
37
+ };
38
+
39
+ const ret = mw(req, res, next);
40
+
41
+ if (ret && typeof ret.then === "function") {
42
+ await ret;
43
+ if (nextError) throw nextError;
44
+ if (res.writableEnded || res.headersSent) return false;
45
+ return nextCalled;
46
+ }
47
+
48
+ if (nextError) throw nextError;
49
+ if (res.writableEnded || res.headersSent) return false;
50
+ if (nextCalled) return true;
51
+
52
+ // A middleware with fewer than 3 declared parameters `(req, res) => {}` cannot call `next`
53
+ if (typeof mw === "function" && mw.length < 3) {
54
+ return false;
55
+ }
56
+
57
+ await new Promise((resolve) => {
58
+ let settled = false;
59
+ let fallbackTimer = null;
60
+ const done = () => {
61
+ if (settled) return;
62
+ settled = true;
63
+ if (fallbackTimer) {
64
+ clearTimeout(fallbackTimer);
65
+ fallbackTimer = null;
66
+ }
67
+ if (typeof res.off === "function") {
68
+ res.off("finish", done);
69
+ res.off("close", done);
70
+ } else if (typeof res.removeListener === "function") {
71
+ res.removeListener("finish", done);
72
+ res.removeListener("close", done);
73
+ }
74
+ resolve();
75
+ };
76
+
77
+ resolveWait = done;
78
+
79
+ if (typeof res.once === "function") {
80
+ res.once("finish", done);
81
+ res.once("close", done);
82
+ } else {
83
+ // Fallback only for synthetic plain-object mocks without EventEmitter methods
84
+ fallbackTimer = setTimeout(done, 100);
85
+ }
86
+ });
87
+
88
+ if (nextError) throw nextError;
89
+ if (res.writableEnded || res.headersSent) return false;
90
+ return nextCalled;
91
+ }
92
+
93
+ /**
94
+ * Runs all registered Node middlewares in sequence.
95
+ * Returns `true` if request processing should continue to Dinou's router,
96
+ * or `false` if a middleware terminated or hijacked the response.
97
+ *
98
+ * @param {Function[]} middlewares
99
+ * @param {import("node:http").IncomingMessage} req
100
+ * @param {import("node:http").ServerResponse} res
101
+ * @returns {Promise<boolean>}
102
+ */
103
+ export async function runNodeMiddlewares(middlewares, req, res) {
104
+ if (!Array.isArray(middlewares) || middlewares.length === 0) {
105
+ return !(res.writableEnded || res.headersSent);
106
+ }
107
+ for (const mw of middlewares) {
108
+ if (res.writableEnded || res.headersSent) {
109
+ return false;
110
+ }
111
+ const shouldContinue = await runSingleNodeMiddleware(mw, req, res);
112
+ if (!shouldContinue || res.writableEnded || res.headersSent) {
113
+ return false;
114
+ }
115
+ }
116
+ return true;
117
+ }
118
+
119
+ /**
120
+ * Invokes `plugin.configureServer` for each configured plugin with per-plugin
121
+ * error isolation so one faulty plugin never blocks subsequent plugins.
122
+ *
123
+ * @param {object} options
124
+ * @param {Array} options.plugins
125
+ * @param {import("node:http").Server} options.server
126
+ * @param {boolean} options.isDev
127
+ * @param {Function[]} options.middlewares
128
+ */
129
+ export async function applyConfigureServerPlugins({
130
+ plugins,
131
+ server,
132
+ isDev,
133
+ middlewares,
134
+ }) {
135
+ if (!Array.isArray(plugins) || plugins.length === 0) {
136
+ return;
137
+ }
138
+ const serverContext = {
139
+ server,
140
+ isDev: Boolean(isDev),
141
+ use(middleware) {
142
+ if (typeof middleware === "function") {
143
+ middlewares.push(middleware);
144
+ }
145
+ },
146
+ };
147
+ for (const plugin of plugins) {
148
+ if (plugin && typeof plugin.configureServer === "function") {
149
+ try {
150
+ await plugin.configureServer(serverContext);
151
+ } catch (err) {
152
+ console.error(
153
+ `[Dinou Plugin Error: "${plugin.name || "unnamed"}" (configureServer)]:`,
154
+ err
155
+ );
156
+ }
157
+ }
158
+ }
159
+ }
160
+
161
+ export default {
162
+ runNodeMiddlewares,
163
+ applyConfigureServerPlugins,
164
+ };
165
+