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,7 @@ export function redirect(destination) {
21
21
  } catch (e) { }
22
22
 
23
23
  // 2. If we are on the server and headers have NOT been sent yet...
24
- // We can do a real HTTP redirect (Status 307 or x-rsc-redirect).
24
+ // We can do a real HTTP redirect (Status 302 or x-rsc-redirect).
25
25
  // This is better for SEO and speed in Hard Navigation.
26
26
  if (ctx && ctx.res && typeof ctx.res.redirect === "function") {
27
27
  ctx.res.redirect(destination);
@@ -16,7 +16,10 @@ import {
16
16
  registerHole,
17
17
  markDynamicAccess,
18
18
  isPageRootElement,
19
+ getPageRootPpr,
19
20
  isLayoutRootElement,
21
+ getLayoutRootPpr,
22
+ runWithSegmentPpr,
20
23
  isLayoutChildrenPlaceholder,
21
24
  runInPageSegment,
22
25
  runInLayoutSegment,
@@ -28,10 +31,20 @@ import {
28
31
  isSlotDiscoveryActive,
29
32
  } from "./ppr-context.js";
30
33
  import { getContext } from "./request-context.js";
34
+ import { unwrapBailoutProxy } from "./bailout-proxy.js";
31
35
 
32
36
  const REACT_MEMO_CACHE_SENTINEL = Symbol.for("react.memo_cache_sentinel");
33
37
  const REACT_CONTEXT_TYPE = Symbol.for("react.context");
34
38
  const CLIENT_REFERENCE_TAG = Symbol.for("react.client.reference");
39
+ const SERVER_HOOKS_IMPL_KEY = Symbol.for("dinou.server.hooks.impl");
40
+ const HOLE_BOUNDARY_PROMISE_CACHE_KEY = Symbol.for(
41
+ "dinou.hole.boundary.promise.cache"
42
+ );
43
+ const REVAL_QUEUE_STORAGE_KEY = Symbol.for("dinou.reval.queue.storage");
44
+
45
+ function isRevalidationActive() {
46
+ return Boolean(globalThis[REVAL_QUEUE_STORAGE_KEY]?.getStore());
47
+ }
35
48
 
36
49
  let fallbackRenderSeq = 0;
37
50
 
@@ -204,6 +217,14 @@ const DinouServerHooksDispatcher = {
204
217
  return unsupportedRefresh;
205
218
  },
206
219
  useEffectEvent: unsupportedHook,
220
+ _dinouIsServerHooksDispatcher: true,
221
+ };
222
+ if (typeof globalThis !== "undefined") {
223
+ globalThis[SERVER_HOOKS_IMPL_KEY] = {
224
+ useServerId,
225
+ snapshotActiveIdCounts,
226
+ restoreActiveIdCounts,
227
+ };
207
228
  };
208
229
 
209
230
  function getCallerComponentSite() {
@@ -227,7 +248,12 @@ function getCallerComponentSite() {
227
248
  }
228
249
 
229
250
  function patchDispatcherObject(dispatcher, internals) {
230
- if (!dispatcher || typeof dispatcher !== "object" || dispatcher === DinouServerHooksDispatcher) {
251
+ if (
252
+ !dispatcher ||
253
+ typeof dispatcher !== "object" ||
254
+ dispatcher === DinouServerHooksDispatcher ||
255
+ dispatcher._dinouIsServerHooksDispatcher
256
+ ) {
231
257
  return;
232
258
  }
233
259
  if (dispatcher._dinouWrappedDispatcher) {
@@ -242,9 +268,14 @@ function patchDispatcherObject(dispatcher, internals) {
242
268
  const owner = internals?.A?.getOwner?.() || getCallerComponentSite();
243
269
  if (owner !== activeOwnerKey || !activeIdSnap) {
244
270
  activeOwnerKey = owner;
245
- activeIdSnap = snapshotActiveIdCounts();
271
+ activeIdSnap = (
272
+ globalThis[SERVER_HOOKS_IMPL_KEY]?.snapshotActiveIdCounts ||
273
+ snapshotActiveIdCounts
274
+ )();
246
275
  }
247
- return useServerId();
276
+ return (
277
+ globalThis[SERVER_HOOKS_IMPL_KEY]?.useServerId || useServerId
278
+ )();
248
279
  };
249
280
  if (origUse && origUse !== useServerUsable) {
250
281
  dispatcher.use = function dinouPatchedUse(usable) {
@@ -253,7 +284,10 @@ function patchDispatcherObject(dispatcher, internals) {
253
284
  return origUse.call(this, usable);
254
285
  } catch (err) {
255
286
  if (activeIdSnap && (!owner || !activeOwnerKey || owner === activeOwnerKey)) {
256
- restoreActiveIdCounts(activeIdSnap);
287
+ (
288
+ globalThis[SERVER_HOOKS_IMPL_KEY]?.restoreActiveIdCounts ||
289
+ restoreActiveIdCounts
290
+ )(activeIdSnap);
257
291
  }
258
292
  activeIdSnap = null;
259
293
  activeOwnerKey = null;
@@ -304,22 +338,23 @@ function getReactInternalsList() {
304
338
  const s = mod.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
305
339
  const c = mod.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
306
340
  if (s && typeof s === "object" && "H" in s) {
341
+ s._dinouIsServerInternals = true;
307
342
  patchInternalsDispatcherSetter(s);
308
343
  set.add(s);
309
344
  }
310
345
  if (c && typeof c === "object" && "H" in c) {
311
- patchInternalsDispatcherSetter(c);
346
+ // Do not install setter on __CLIENT_INTERNALS__ (used by react-dom/server SSR)
312
347
  set.add(c);
313
348
  }
314
349
  };
315
350
  addFromModule(React);
316
351
  try {
317
- const req = createRequire(import.meta.url);
352
+ const createReq = createRequire; const req = createReq(import.meta.url); const reactPkgPath = req.resolve("react/package.json"); const reactDir = reactPkgPath.slice(0, reactPkgPath.length - "package.json".length);
318
353
  try {
319
- addFromModule(req("react/index.js"));
354
+ addFromModule(req(reactDir + "index.js"));
320
355
  } catch (_) {}
321
356
  try {
322
- addFromModule(req("react/react.react-server.js"));
357
+ addFromModule(req(reactDir + "react.react-server.js"));
323
358
  } catch (_) {}
324
359
  } catch (_) {}
325
360
  _cachedReactInternalsList = Array.from(set);
@@ -329,7 +364,7 @@ function getReactInternalsList() {
329
364
  function ensureServerHooksPatched() {
330
365
  const list = getReactInternalsList();
331
366
  for (const internals of list) {
332
- patchInternalsDispatcherSetter(internals);
367
+ if (internals._dinouIsServerInternals) patchInternalsDispatcherSetter(internals);
333
368
  }
334
369
  }
335
370
 
@@ -354,12 +389,12 @@ function isThenable(val) {
354
389
  return (
355
390
  val !== null &&
356
391
  (typeof val === "object" || typeof val === "function") &&
357
- typeof val.then === "function"
392
+ val.$$typeof !== CLIENT_REFERENCE_TAG && !isClientComponent(val) && typeof val.then === "function"
358
393
  );
359
394
  }
360
395
 
361
396
  function isCacheSlotComponent(fn) {
362
- if (!fn) return false;
397
+ if (!fn || fn.$$typeof === CLIENT_REFERENCE_TAG || isClientComponent(fn)) return false;
363
398
  return Boolean(fn.$$dinouCacheSlot || fn.name === "DinouCacheSlot");
364
399
  }
365
400
 
@@ -483,7 +518,14 @@ function replaceLayoutChildrenPlaceholder(node, replacement, placeholder) {
483
518
  }
484
519
  return node;
485
520
  }
486
- if (node instanceof Promise) return node;
521
+ if (
522
+ node instanceof Promise ||
523
+ isThenable(node) ||
524
+ node.$$typeof === CLIENT_REFERENCE_TAG ||
525
+ isClientComponent(node)
526
+ ) {
527
+ return node;
528
+ }
487
529
  let changed = false;
488
530
  const clone = { ...node };
489
531
  for (const [k, v] of Object.entries(node)) {
@@ -510,38 +552,102 @@ function isClientComponent(type) {
510
552
  );
511
553
  }
512
554
 
513
- async function DinouSuspenseHoleBoundary({ holeId, children }) {
514
- return await runInRuntimeDynamicHole(
555
+ if (!globalThis[HOLE_BOUNDARY_PROMISE_CACHE_KEY]) {
556
+ globalThis[HOLE_BOUNDARY_PROMISE_CACHE_KEY] = new WeakMap();
557
+ }
558
+ const holeBoundaryPromiseCache = globalThis[HOLE_BOUNDARY_PROMISE_CACHE_KEY];
559
+ async function DinouSuspenseHoleBoundary(props) {
560
+ if (props && typeof props === "object" && holeBoundaryPromiseCache.has(props)) {
561
+ return await holeBoundaryPromiseCache.get(props);
562
+ }
563
+ const { holeId, children } = props || {};
564
+ const promise = runInRuntimeDynamicHole(
515
565
  () => asyncRenderJSXToClientJSX(children),
516
566
  holeId
517
567
  );
568
+ if (props && typeof props === "object") {
569
+ holeBoundaryPromiseCache.set(props, promise);
570
+ }
571
+ return await promise;
572
+ }
573
+ DinouSuspenseHoleBoundary.$$dinouDeferredSuspenseStream = true;
574
+
575
+ function attachSilentRejectionHandler(node) {
576
+ if (!node) return;
577
+ if (isThenable(node)) {
578
+ try {
579
+ node.then(null, () => {});
580
+ } catch (_) {}
581
+ return;
582
+ }
583
+ if (Array.isArray(node)) {
584
+ for (const item of node) {
585
+ attachSilentRejectionHandler(item);
586
+ }
587
+ }
588
+ }
589
+
590
+ function handlePprThenableAccess(thenable) {
591
+ if (
592
+ isPprBuildActive() &&
593
+ isInsideOuterSuspenseOutsideSlot() &&
594
+ !isSlotDiscoveryActive() &&
595
+ !isNoDynamicActive()
596
+ ) {
597
+ try {
598
+ thenable.then(null, () => {});
599
+ } catch (_) {}
600
+ markDynamicAccess("async-suspense");
601
+ }
518
602
  }
519
603
 
520
- async function asyncRenderJSXToClientJSX(jsx, key = null) {
604
+ async function asyncRenderJSXToClientJSX(
605
+ jsx,
606
+ key = null,
607
+ insideClientProps = false
608
+ ) {
521
609
  if (isPageRootElement(jsx)) {
522
- return await runInPageSegment(async () => {
523
- const resolved = await asyncRenderJSXToClientJSXInner(jsx, key);
524
- const ctx = getContext();
525
- if (ctx && getPprStore()) {
526
- ctx._resolvedPageClientJsx = resolved;
527
- }
528
- return resolved;
529
- });
610
+ const pagePpr = getPageRootPpr(jsx);
611
+ return await runWithSegmentPpr(pagePpr, () =>
612
+ runInPageSegment(async () => {
613
+ const resolved = await asyncRenderJSXToClientJSXInner(
614
+ jsx,
615
+ key,
616
+ insideClientProps
617
+ );
618
+ const ctx = getContext();
619
+ if (ctx) {
620
+ ctx._resolvedPageClientJsx = resolved;
621
+ }
622
+ return resolved;
623
+ })
624
+ );
530
625
  }
531
626
  if (isLayoutRootElement(jsx)) {
532
- return await runInLayoutSegment(async () => {
533
- return await asyncRenderJSXToClientJSXInner(jsx, key);
534
- });
627
+ const layoutPpr = getLayoutRootPpr(jsx);
628
+ return await runWithSegmentPpr(layoutPpr, () =>
629
+ runInLayoutSegment(async () => {
630
+ return await asyncRenderJSXToClientJSXInner(
631
+ jsx,
632
+ key,
633
+ insideClientProps
634
+ );
635
+ })
636
+ );
535
637
  }
536
- return await asyncRenderJSXToClientJSXInner(jsx, key);
638
+ return await asyncRenderJSXToClientJSXInner(jsx, key, insideClientProps);
537
639
  }
538
640
 
539
- async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
641
+ async function asyncRenderJSXToClientJSXInner(
642
+ jsx,
643
+ key = null,
644
+ insideClientProps = false
645
+ ) {
540
646
  if (
541
647
  typeof jsx === "string" ||
542
648
  typeof jsx === "number" ||
543
649
  typeof jsx === "boolean" ||
544
- typeof jsx === "function" ||
650
+ (typeof jsx === "function" && !isThenable(jsx)) ||
545
651
  typeof jsx === "undefined" ||
546
652
  jsx === null
547
653
  ) {
@@ -549,9 +655,29 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
549
655
  } else if (Array.isArray(jsx)) {
550
656
  const results = [];
551
657
  for (const child of jsx) {
552
- results.push(await asyncRenderJSXToClientJSX(child, child?.key ?? null));
658
+ if (isThenable(child)) {
659
+ handlePprThenableAccess(child);
660
+ if (insideClientProps) {
661
+ results.push(child);
662
+ continue;
663
+ }
664
+ }
665
+ results.push(
666
+ await asyncRenderJSXToClientJSX(
667
+ child,
668
+ child?.key ?? null,
669
+ insideClientProps
670
+ )
671
+ );
553
672
  }
554
673
  return results;
674
+ } else if (isThenable(jsx)) {
675
+ handlePprThenableAccess(jsx);
676
+ if (insideClientProps) {
677
+ return jsx;
678
+ }
679
+ const resolved = await jsx;
680
+ return await asyncRenderJSXToClientJSX(resolved, key, false);
555
681
  } else if (typeof jsx === "symbol") {
556
682
  if (jsx === Symbol.for("react.fragment")) {
557
683
  // Handle Fragment as an empty props object
@@ -560,7 +686,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
560
686
  console.error("Unsupported symbol:", String(jsx));
561
687
  throw new Error(`Unsupported symbol: ${String(jsx)}`);
562
688
  } else if (typeof jsx === "object") {
563
- if (isLayoutChildrenPlaceholder(jsx)) {
689
+ if (
690
+ isLayoutChildrenPlaceholder(jsx) ||
691
+ jsx.$$typeof === CLIENT_REFERENCE_TAG ||
692
+ isClientComponent(jsx)
693
+ ) {
564
694
  return jsx;
565
695
  }
566
696
  if (jsx.$$typeof === Symbol.for("react.transitional.element")) {
@@ -627,16 +757,28 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
627
757
  return await runInSuspense(async () => {
628
758
  return cloneWithDevProps(
629
759
  jsx,
630
- await asyncRenderJSXToClientJSX(jsx.props),
760
+ await asyncRenderJSXToClientJSX(jsx.props, null, false),
631
761
  key ?? jsx.key
632
762
  );
633
763
  });
634
764
  }
765
+ const reqCtx = getContext();
766
+ const rawQuery = unwrapBailoutProxy(reqCtx?.req?.query);
767
+ const shouldStreamDynamicSuspense =
768
+ !isPprBuildActive() &&
769
+ !getPprStore() &&
770
+ !getActiveRuntimeDynamicHoleStore() &&
771
+ !reqCtx?.platformContext?.isSSG &&
772
+ !reqCtx?._isStaticHtmlRender &&
773
+ !reqCtx?._isPprRuntimeResume &&
774
+ !isRevalidationActive() &&
775
+ !isSlotDiscoveryActive() &&
776
+ (Boolean(reqCtx?._dynamicState?.value) ||
777
+ Object.keys(rawQuery || {}).length > 0 ||
778
+ process.env.DINOU_DEV === "true" ||
779
+ process.env.NODE_ENV !== "production");
635
780
  const shouldEagerlyResolveSuspense =
636
- Boolean(getPprStore()) ||
637
- Boolean(getActiveRuntimeDynamicHoleStore()) ||
638
- Boolean(getContext()?.platformContext?.isSSG) ||
639
- process.env.NODE_ENV === "production" ||
781
+ !shouldStreamDynamicSuspense ||
640
782
  containsCacheSlot(jsx.props?.children);
641
783
  if (shouldEagerlyResolveSuspense) {
642
784
  return await runInSuspense(async (holeId) => {
@@ -656,9 +798,14 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
656
798
  );
657
799
  });
658
800
  }
659
- if (jsx.props?.children?.type === DinouSuspenseHoleBoundary) {
801
+ if (
802
+ jsx.props?.children?.type === DinouSuspenseHoleBoundary ||
803
+ (!isClientComponent(jsx.props?.children?.type) &&
804
+ jsx.props?.children?.type?.$$dinouDeferredSuspenseStream)
805
+ ) {
660
806
  return jsx;
661
807
  }
808
+ attachSilentRejectionHandler(jsx.props?.children);
662
809
  return await runInSuspense(async (holeId) => {
663
810
  const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
664
811
  return cloneWithDevProps(
@@ -681,7 +828,7 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
681
828
  ) {
682
829
  return cloneWithDevProps(
683
830
  jsx,
684
- await asyncRenderJSXToClientJSX(jsx.props),
831
+ await asyncRenderJSXToClientJSX(jsx.props, null, false),
685
832
  key ?? jsx.key
686
833
  );
687
834
  } else if (typeof jsx.type === "function") {
@@ -698,7 +845,7 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
698
845
  }
699
846
  return cloneWithDevProps(
700
847
  jsx,
701
- await asyncRenderJSXToClientJSX(props),
848
+ await asyncRenderJSXToClientJSX(props, null, true),
702
849
  key ?? jsx.key,
703
850
  Component
704
851
  );
@@ -709,7 +856,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
709
856
  const returnedJsx = await invokeServerComponentInPpr(Component, () =>
710
857
  Component(props)
711
858
  );
712
- return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
859
+ return await asyncRenderJSXToClientJSX(
860
+ returnedJsx,
861
+ key ?? jsx.key,
862
+ false
863
+ );
713
864
  }
714
865
  } else if (
715
866
  typeof jsx.type === "object" &&
@@ -719,7 +870,7 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
719
870
  if (isClientComponent(jsx.type)) {
720
871
  return cloneWithDevProps(
721
872
  jsx,
722
- await asyncRenderJSXToClientJSX(jsx.props),
873
+ await asyncRenderJSXToClientJSX(jsx.props, null, true),
723
874
  key ?? jsx.key,
724
875
  jsx.type
725
876
  );
@@ -728,7 +879,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
728
879
  jsx.type.render,
729
880
  () => jsx.type.render(jsx.props, jsx.ref)
730
881
  );
731
- return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
882
+ return await asyncRenderJSXToClientJSX(
883
+ returnedJsx,
884
+ key ?? jsx.key,
885
+ false
886
+ );
732
887
  }
733
888
  } else if (
734
889
  typeof jsx.type === "object" &&
@@ -738,7 +893,7 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
738
893
  if (isClientComponent(jsx.type)) {
739
894
  return cloneWithDevProps(
740
895
  jsx,
741
- await asyncRenderJSXToClientJSX(jsx.props),
896
+ await asyncRenderJSXToClientJSX(jsx.props, null, true),
742
897
  key ?? jsx.key,
743
898
  jsx.type
744
899
  );
@@ -748,12 +903,17 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
748
903
  const returnedJsx = await invokeServerComponentInPpr(innerComp, () =>
749
904
  innerComp(jsx.props)
750
905
  );
751
- return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
906
+ return await asyncRenderJSXToClientJSX(
907
+ returnedJsx,
908
+ key ?? jsx.key,
909
+ false
910
+ );
752
911
  }
753
912
  if (typeof innerComp === "object" && innerComp !== null) {
754
913
  return await asyncRenderJSXToClientJSX(
755
914
  cloneWithDevProps(jsx, jsx.props, key ?? jsx.key, innerComp),
756
- key ?? jsx.key
915
+ key ?? jsx.key,
916
+ false
757
917
  );
758
918
  }
759
919
  return null;
@@ -762,13 +922,21 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
762
922
  console.error("Unsupported JSX type:", jsx.type);
763
923
  throw new Error("Unsupported JSX type");
764
924
  }
765
- } else if (jsx instanceof Promise) {
766
- return jsx;
767
925
  } else {
768
926
  // Process object props (e.g., { className: "foo" })
769
927
  const entries = [];
770
928
  for (const [propName, value] of Object.entries(jsx)) {
771
- entries.push([propName, await asyncRenderJSXToClientJSX(value)]);
929
+ if (isThenable(value)) {
930
+ handlePprThenableAccess(value);
931
+ if (insideClientProps) {
932
+ entries.push([propName, value]);
933
+ continue;
934
+ }
935
+ }
936
+ entries.push([
937
+ propName,
938
+ await asyncRenderJSXToClientJSX(value, null, insideClientProps),
939
+ ]);
772
940
  }
773
941
  return Object.fromEntries(entries);
774
942
  }
@@ -1,4 +1,6 @@
1
1
  // dinou/core/request-context.js
2
+ import { createUnifiedEnv } from "./runtime-env.js";
3
+
2
4
  const DINOU_CONTEXT_KEY = Symbol.for("dinou.request.context.storage");
3
5
  let requestStorage;
4
6
 
@@ -12,6 +14,8 @@ if (typeof window === "undefined") {
12
14
  try {
13
15
  if (typeof globalThis.__dinou_require__ === "function") {
14
16
  AsyncLocalStorageClass = globalThis.__dinou_require__("node:async_hooks")?.AsyncLocalStorage;
17
+ } else if (typeof process !== "undefined" && typeof process.getBuiltinModule === "function") {
18
+ AsyncLocalStorageClass = process.getBuiltinModule("node:async_hooks")?.AsyncLocalStorage;
15
19
  } else if (typeof process !== "undefined" && process.versions && (process.versions.node || process.versions.bun)) {
16
20
  const getRequire = new Function("return typeof require !== 'undefined' ? require : null");
17
21
  const nodeRequire = getRequire();
@@ -56,15 +60,67 @@ function getCurrentContext() {
56
60
  return undefined;
57
61
  }
58
62
 
63
+ const noopResponseProxy = Object.freeze({
64
+ cookie() {},
65
+ clearCookie() {},
66
+ setHeader() {},
67
+ redirect() {},
68
+ status() {},
69
+ });
70
+
71
+ function createFallbackServerContext() {
72
+ const unifiedEnv = createUnifiedEnv();
73
+ return {
74
+ req: {
75
+ query: {},
76
+ cookies: {},
77
+ headers: {},
78
+ path: "/",
79
+ rawPath: "/",
80
+ isRscRequest: false,
81
+ method: "GET",
82
+ env: unifiedEnv,
83
+ ctx: null,
84
+ },
85
+ res: noopResponseProxy,
86
+ env: unifiedEnv,
87
+ ctx: null,
88
+ };
89
+ }
90
+
59
91
  function getContext() {
60
92
  if (typeof window !== "undefined") {
61
93
  console.error(
62
94
  "[Dinou] ❌ You are calling getContext() inside a Client Component running in the browser. This function is Server-Only. Pass the data as props from a Server Component instead."
63
95
  );
64
- return {};
96
+ return {
97
+ req: {
98
+ query: {},
99
+ cookies: {},
100
+ headers: {},
101
+ path: "/",
102
+ rawPath: "/",
103
+ isRscRequest: false,
104
+ method: "GET",
105
+ env: {},
106
+ ctx: null,
107
+ },
108
+ res: noopResponseProxy,
109
+ env: {},
110
+ ctx: null,
111
+ };
112
+ }
113
+ const store = requestStorage?.getStore() || getCurrentContext();
114
+ if (store) {
115
+ if (!store.env) {
116
+ store.env = createUnifiedEnv(store.platformContext?.env);
117
+ }
118
+ if (store.req && !store.req.env) {
119
+ store.req.env = store.env;
120
+ }
121
+ return store;
65
122
  }
66
- const store = requestStorage?.getStore();
67
- return store || getCurrentContext() || {};
123
+ return createFallbackServerContext();
68
124
  }
69
125
 
70
126
  export {