dinou 9.0.3 → 9.1.0

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.
package/dinou/cli.js CHANGED
@@ -14,7 +14,7 @@ const projectRoot = process.cwd();
14
14
  program
15
15
  .name("dinou")
16
16
  .description("Full-stack React 19 framework with native RSC, progressive streaming, and dual-mode vendoring")
17
- .version("9.0.3")
17
+ .version("9.1.0")
18
18
  .option("-u, --unvendorized", "Run with standard node_modules dependencies instead of pre-bundled vendor packages");
19
19
 
20
20
  const isUnvendorizedRequested = () =>
@@ -1,7 +1,7 @@
1
- import { isPprBuildActive, isInsideSuspense, markDynamicAccess } from "./ppr-context.js";
1
+ import { isPprBuildActive, isInsideOuterSuspenseOutsideSlot, markDynamicAccess } from "./ppr-context.js";
2
2
 
3
3
  function triggerBailout(label, onBailout) {
4
- if (isPprBuildActive() && isInsideSuspense()) {
4
+ if (isPprBuildActive() && isInsideOuterSuspenseOutsideSlot()) {
5
5
  markDynamicAccess(label);
6
6
  } else if (typeof onBailout === "function") {
7
7
  onBailout();
@@ -912,6 +912,7 @@ async function buildStaticPages(onProgress = null) {
912
912
  const mockContext = {
913
913
  req: mockReq,
914
914
  res: mockRes,
915
+ _markDynamic: markAsDynamic,
915
916
  };
916
917
 
917
918
  let revalidate;
@@ -1274,6 +1275,7 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1274
1275
  const mockContext = {
1275
1276
  req: mockReq,
1276
1277
  res: mockRes,
1278
+ _markDynamic: markAsDynamic,
1277
1279
  };
1278
1280
 
1279
1281
  let revalidate;
@@ -79,6 +79,43 @@ function enqueueRevalidation(fn) {
79
79
  return nextPromise;
80
80
  }
81
81
 
82
+ async function readEdgeStorageOrAsset(storage, key) {
83
+ if (!storage || !key) return null;
84
+ try {
85
+ const item = await storage.get(key);
86
+ if (item && item.content) return item;
87
+ } catch (e) {}
88
+ if (typeof storage.isDeleted === "function" && storage.isDeleted(key)) {
89
+ return null;
90
+ }
91
+ try {
92
+ const reqContext = getContext();
93
+ const assets =
94
+ reqContext?.env?.ASSETS ||
95
+ reqContext?.platformContext?.env?.ASSETS ||
96
+ reqContext?.req?.env?.ASSETS ||
97
+ (typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__?.ASSETS : null);
98
+ if (assets && typeof assets.fetch === "function") {
99
+ const cleanKey = String(key).replace(/^\/+/, "");
100
+ const res = await assets.fetch(new Request(`http://localhost/${cleanKey}`));
101
+ if (res && res.status === 200) {
102
+ const ct = res.headers?.get?.("content-type") || "";
103
+ const content = await res.text();
104
+ const isHtmlExpected = cleanKey.endsWith(".html");
105
+ if (
106
+ content &&
107
+ (isHtmlExpected || (!ct.includes("text/html") && !content.trimStart().startsWith("<")))
108
+ ) {
109
+ const item = { content };
110
+ await storage.set(cleanKey, content);
111
+ return item;
112
+ }
113
+ }
114
+ }
115
+ } catch (e) {}
116
+ return null;
117
+ }
118
+
82
119
  async function resolveRouteConfigForRevalidate(pagePath, reqSegments, existingMeta = {}) {
83
120
  const srcFolder = path.resolve(process.cwd(), "src");
84
121
  let isRoutePpr =
@@ -274,9 +311,12 @@ async function revalidatePage(reqPath, internalOptions = {}) {
274
311
  if (!cached) {
275
312
  cached = await storage.get(shellHtmlKey);
276
313
  }
314
+ if (!cached) {
315
+ cached = await readEdgeStorageOrAsset(storage, htmlKey);
316
+ }
277
317
  let currentMeta = (cached && cached.metadata) || {};
278
318
  try {
279
- const metaItem = await storage.get(metaKey);
319
+ const metaItem = await readEdgeStorageOrAsset(storage, metaKey);
280
320
  if (metaItem && metaItem.content) {
281
321
  currentMeta = JSON.parse(metaItem.content);
282
322
  }
@@ -284,7 +324,7 @@ async function revalidatePage(reqPath, internalOptions = {}) {
284
324
 
285
325
  let existingPageRsc = null;
286
326
  try {
287
- existingPageRsc = await storage.get(rscKey);
327
+ existingPageRsc = await readEdgeStorageOrAsset(storage, rscKey);
288
328
  } catch (e) {}
289
329
 
290
330
  const reqPathWithSlash = cleanPath.endsWith("/") ? cleanPath : cleanPath + "/";
@@ -322,7 +362,7 @@ async function revalidatePage(reqPath, internalOptions = {}) {
322
362
  const lMetaKey = entry.cleanLayoutKey
323
363
  ? `${entry.cleanLayoutKey}/layout.metadata.json`
324
364
  : "layout.metadata.json";
325
- const lItem = await storage.get(lMetaKey);
365
+ const lItem = await readEdgeStorageOrAsset(storage, lMetaKey);
326
366
  let lMetaObj = lItem?.metadata || null;
327
367
  if (!lMetaObj && lItem?.content) {
328
368
  try {
@@ -343,7 +383,7 @@ async function revalidatePage(reqPath, internalOptions = {}) {
343
383
  const refreshedMetaKey = leafLayout.cleanLayoutKey
344
384
  ? `${leafLayout.cleanLayoutKey}/layout.metadata.json`
345
385
  : "layout.metadata.json";
346
- const refreshedItem = await storage.get(refreshedMetaKey);
386
+ const refreshedItem = await readEdgeStorageOrAsset(storage, refreshedMetaKey);
347
387
  if (refreshedItem?.content) {
348
388
  try {
349
389
  const parsed = JSON.parse(refreshedItem.content);
@@ -361,7 +401,7 @@ async function revalidatePage(reqPath, internalOptions = {}) {
361
401
  const leafRscKey = leafLayout.cleanLayoutKey
362
402
  ? `${leafLayout.cleanLayoutKey}/layout.rsc`
363
403
  : "layout.rsc";
364
- const leafRscItem = await storage.get(leafRscKey);
404
+ const leafRscItem = await readEdgeStorageOrAsset(storage, leafRscKey);
365
405
  if (leafRscItem && leafRscItem.content && !leafRscItem.content.trimStart().startsWith("<")) {
366
406
  activeLayoutRscText = leafRscItem.content;
367
407
  }
@@ -389,6 +429,13 @@ async function revalidatePage(reqPath, internalOptions = {}) {
389
429
  const markRevalDynamic = () => {
390
430
  revalDynamicState.value = true;
391
431
  };
432
+ const outerCtx = getContext();
433
+ const activeEnv =
434
+ outerCtx?.env ||
435
+ outerCtx?.platformContext?.env ||
436
+ outerCtx?.req?.env ||
437
+ (typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__ : undefined) ||
438
+ {};
392
439
  const revalContext = {
393
440
  req: {
394
441
  query: createBailoutProxy({}, "req.query", markRevalDynamic),
@@ -396,6 +443,7 @@ async function revalidatePage(reqPath, internalOptions = {}) {
396
443
  headers: createBailoutProxy(rawHeaders, "req.headers", markRevalDynamic),
397
444
  path: reqPathWithSlash,
398
445
  method: "GET",
446
+ env: activeEnv,
399
447
  },
400
448
  res: {
401
449
  status() {},
@@ -412,6 +460,8 @@ async function revalidatePage(reqPath, internalOptions = {}) {
412
460
  markRevalDynamic();
413
461
  },
414
462
  },
463
+ env: activeEnv,
464
+ platformContext: outerCtx?.platformContext || { env: activeEnv },
415
465
  };
416
466
  const clientManifest =
417
467
  (typeof globalThis !== "undefined" && globalThis.__DINOU_CLIENT_MANIFEST__) || {};
@@ -423,7 +473,7 @@ async function revalidatePage(reqPath, internalOptions = {}) {
423
473
 
424
474
  if (onlyRefreshSlots) {
425
475
  try {
426
- const existingShellPage = await storage.get(shellPageKey);
476
+ const existingShellPage = await readEdgeStorageOrAsset(storage, shellPageKey);
427
477
  if (existingShellPage && existingShellPage.content) {
428
478
  const deserialized = deserializeJSX(existingShellPage.content);
429
479
  resolvedPageJsx = await runInPageSegment(() =>
@@ -811,10 +861,10 @@ async function revalidateLayout(cleanPath, internalOptions = {}) {
811
861
  const layoutMetaKey = cleanPathKey ? `${cleanPathKey}/layout.metadata.json` : "layout.metadata.json";
812
862
  const shellLayoutKey = cleanPathKey ? `${cleanPathKey}/shell.layout.json` : "shell.layout.json";
813
863
 
814
- let cached = await storage.get(layoutRscKey);
864
+ let cached = await readEdgeStorageOrAsset(storage, layoutRscKey);
815
865
  let currentMeta = (cached && cached.metadata) || {};
816
866
  try {
817
- const metaItem = await storage.get(layoutMetaKey);
867
+ const metaItem = await readEdgeStorageOrAsset(storage, layoutMetaKey);
818
868
  if (metaItem && metaItem.content) {
819
869
  currentMeta = JSON.parse(metaItem.content);
820
870
  }
@@ -853,6 +903,10 @@ async function revalidateLayout(cleanPath, internalOptions = {}) {
853
903
  currentMeta.ppr = Boolean(layoutCfg.ppr);
854
904
  }
855
905
  }
906
+ if (typeof currentMeta.ppr !== "boolean") {
907
+ const layoutRouteCfg = await resolveRouteConfigForRevalidate(null, reqSegments, currentMeta);
908
+ currentMeta.ppr = Boolean(layoutRouteCfg.isRoutePpr);
909
+ }
856
910
  } catch (e) {}
857
911
 
858
912
  const prevGenTime = (currentMeta && currentMeta.generatedAt) || 0;
@@ -875,6 +929,13 @@ async function revalidateLayout(cleanPath, internalOptions = {}) {
875
929
  const markRevalDynamic = () => {
876
930
  revalDynamicState.value = true;
877
931
  };
932
+ const outerCtx = getContext();
933
+ const activeEnv =
934
+ outerCtx?.env ||
935
+ outerCtx?.platformContext?.env ||
936
+ outerCtx?.req?.env ||
937
+ (typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__ : undefined) ||
938
+ {};
878
939
  const revalContext = {
879
940
  req: {
880
941
  query: createBailoutProxy({}, "req.query", markRevalDynamic),
@@ -882,6 +943,7 @@ async function revalidateLayout(cleanPath, internalOptions = {}) {
882
943
  headers: createBailoutProxy(rawHeaders, "req.headers", markRevalDynamic),
883
944
  path: reqPathWithSlash,
884
945
  method: "GET",
946
+ env: activeEnv,
885
947
  },
886
948
  res: {
887
949
  status() {},
@@ -898,6 +960,8 @@ async function revalidateLayout(cleanPath, internalOptions = {}) {
898
960
  markRevalDynamic();
899
961
  },
900
962
  },
963
+ env: activeEnv,
964
+ platformContext: outerCtx?.platformContext || { env: activeEnv },
901
965
  };
902
966
  const clientManifest =
903
967
  (typeof globalThis !== "undefined" && globalThis.__DINOU_CLIENT_MANIFEST__) || {};
@@ -905,7 +969,7 @@ async function revalidateLayout(cleanPath, internalOptions = {}) {
905
969
  let resolvedLayoutJsx = null;
906
970
  if (onlyRefreshSlots) {
907
971
  try {
908
- const existingShellLayout = await storage.get(shellLayoutKey);
972
+ const existingShellLayout = await readEdgeStorageOrAsset(storage, shellLayoutKey);
909
973
  if (existingShellLayout && existingShellLayout.content) {
910
974
  const deserialized = deserializeJSX(existingShellLayout.content);
911
975
  resolvedLayoutJsx = await runInLayoutSegment(() =>
@@ -922,7 +986,10 @@ async function revalidateLayout(cleanPath, internalOptions = {}) {
922
986
  }
923
987
  }
924
988
  if (!resolvedLayoutJsx) {
925
- await runWithPprContext({ isPpr: true }, async () => {
989
+ const isLayoutPpr = Boolean(
990
+ currentMeta.ppr || (Array.isArray(currentMeta.holes) && currentMeta.holes.length > 0)
991
+ );
992
+ await runWithPprContext({ isPpr: isLayoutPpr }, async () => {
926
993
  const rawJsx = await getJSX(reqPathWithSlash, {}, {}, false, false, {
927
994
  segment: "layout",
928
995
  });
@@ -13,18 +13,17 @@ import { getJSX } from "./get-jsx.js";
13
13
  import {
14
14
  isPprBuildActive,
15
15
  isInsideSuspense,
16
+ isInsideOuterSuspenseOutsideSlot,
16
17
  deferPprSuspenseEffect,
17
18
  runWithPprContext,
18
19
  isInsideLayoutSegment,
19
20
  isInsidePageSegment,
21
+ markDynamicAccess,
22
+ runInCachedSlot,
23
+ runInSlotDiscovery,
24
+ isSlotDiscoveryActive,
20
25
  } from "./ppr-context.js";
21
26
  import { createRequire } from "node:module";
22
- import { AsyncLocalStorage } from "node:async_hooks";
23
-
24
- const slotDiscoveryStorage = new AsyncLocalStorage();
25
- function isSlotDiscoveryActive() {
26
- return Boolean(slotDiscoveryStorage.getStore()?.active);
27
- }
28
27
 
29
28
  const require = createRequire(import.meta.url);
30
29
  const currentDir = path.dirname(fileURLToPath(import.meta.url));
@@ -47,6 +46,11 @@ if (!globalThis[RECENT_FRESH_KEY]) {
47
46
  }
48
47
  const recentFreshSlotRenders = globalThis[RECENT_FRESH_KEY];
49
48
 
49
+ const REVAL_QUEUE_STORAGE_KEY = Symbol.for("dinou.reval.queue.storage");
50
+ function isRevalidationActive() {
51
+ return Boolean(globalThis[REVAL_QUEUE_STORAGE_KEY]?.getStore());
52
+ }
53
+
50
54
  const BG_REVAL_KEY = Symbol.for("dinou.slot.background.revalidations");
51
55
  if (!globalThis[BG_REVAL_KEY]) {
52
56
  globalThis[BG_REVAL_KEY] = new Set();
@@ -346,7 +350,8 @@ async function getSlotFromStorage(storage, storageKey, knownTags = []) {
346
350
  const assets =
347
351
  reqContext?.env?.ASSETS ||
348
352
  reqContext?.platformContext?.env?.ASSETS ||
349
- reqContext?.req?.env?.ASSETS;
353
+ reqContext?.req?.env?.ASSETS ||
354
+ (typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__?.ASSETS : null);
350
355
  if (assets && typeof assets.fetch === "function") {
351
356
  const cleanKey = String(storageKey || "").replace(/^\/+/, "");
352
357
  const metaKey = cleanKey.endsWith("/slot.json")
@@ -390,6 +395,37 @@ async function getSlotFromStorage(storage, storageKey, knownTags = []) {
390
395
  return cached;
391
396
  }
392
397
 
398
+ async function readMetaFromStorageOrAssets(storage, key) {
399
+ if (!storage || !key) return null;
400
+ try {
401
+ const item = await storage.get(key);
402
+ if (item?.metadata && typeof item.metadata === "object") return item.metadata;
403
+ if (item?.content) return JSON.parse(item.content);
404
+ } catch (e) {}
405
+ if (typeof storage.isDeleted === "function" && storage.isDeleted(key)) return null;
406
+ try {
407
+ const reqContext = getContext();
408
+ const assets =
409
+ reqContext?.env?.ASSETS ||
410
+ reqContext?.platformContext?.env?.ASSETS ||
411
+ reqContext?.req?.env?.ASSETS ||
412
+ (typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__?.ASSETS : null);
413
+ if (assets && typeof assets.fetch === "function") {
414
+ const cleanKey = String(key).replace(/^\/+/, "");
415
+ const res = await assets.fetch(new Request(`http://localhost/${cleanKey}`));
416
+ if (res && res.status === 200) {
417
+ const text = await res.text();
418
+ if (text && text.trimStart().startsWith("{")) {
419
+ const parsed = JSON.parse(text);
420
+ await storage.set(cleanKey, text);
421
+ return parsed;
422
+ }
423
+ }
424
+ }
425
+ } catch (e) {}
426
+ return null;
427
+ }
428
+
393
429
  /**
394
430
  * Traverses a deserialized JSX tree from a cached outer slot and refreshes
395
431
  * any nested <DinouCacheSlot> boundaries so inner slot invalidations are
@@ -479,10 +515,24 @@ async function refreshNestedSlotsInTree(node, currentSlotId, options = {}) {
479
515
  */
480
516
  async function DinouCacheSlot(props) {
481
517
  const { id, tag, tags, revalidate, children } = props || {};
518
+ const isNoCache = typeof revalidate === "number" && revalidate < 1;
482
519
 
483
520
  const slotId = id || tag || (Array.isArray(tags) ? tags[0] : null);
484
521
  if (!slotId) {
485
- return typeof children === "function" ? await children() : children;
522
+ if (isNoCache && !isSlotDiscoveryActive()) {
523
+ if (isPprBuildActive() && isInsideOuterSuspenseOutsideSlot()) {
524
+ markDynamicAccess("slot-revalidate-0");
525
+ } else {
526
+ try {
527
+ getContext()?._markDynamic?.();
528
+ } catch (e) {}
529
+ }
530
+ }
531
+ const runScope = isNoCache ? (fn) => fn() : runInCachedSlot;
532
+ return await runScope(async () => {
533
+ const childElement = typeof children === "function" ? await children() : children;
534
+ return await asyncRenderJSXToClientJSX(childElement);
535
+ });
486
536
  }
487
537
 
488
538
  const allTags = Array.isArray(tags)
@@ -494,7 +544,7 @@ async function DinouCacheSlot(props) {
494
544
 
495
545
  const storageKey = `slots/${slotId}/slot.json`;
496
546
  const storage = getStorageAdapter();
497
- const isNoCache = revalidate === 0;
547
+ const runSlotScope = isNoCache ? (fn) => fn() : runInCachedSlot;
498
548
 
499
549
  function wrapWithBoundary(content, alreadyRendered = false) {
500
550
  const Boundary = getCacheSlotBoundary();
@@ -523,14 +573,16 @@ async function DinouCacheSlot(props) {
523
573
  // Register in slotRegistry for on-demand endpoint re-rendering and nested slot discovery
524
574
  slotRegistry.set(slotId, {
525
575
  render: async () => {
526
- const childElement = typeof children === "function" ? await children() : children;
527
- return await asyncRenderJSXToClientJSX(childElement);
576
+ return await runSlotScope(async () => {
577
+ const childElement = typeof children === "function" ? await children() : children;
578
+ return await asyncRenderJSXToClientJSX(childElement);
579
+ });
528
580
  },
529
581
  discover: async () => {
530
582
  if (discoveringSlots.has(slotId)) return;
531
583
  discoveringSlots.add(slotId);
532
584
  try {
533
- await slotDiscoveryStorage.run({ active: true }, async () => {
585
+ await runInSlotDiscovery(async () => {
534
586
  const childElement = typeof children === "function" ? await children() : children;
535
587
  await asyncRenderJSXToClientJSX(childElement);
536
588
  });
@@ -551,9 +603,21 @@ async function DinouCacheSlot(props) {
551
603
  }
552
604
  }
553
605
 
606
+ if (isNoCache && !isSlotDiscoveryActive()) {
607
+ if (isPprBuildActive() && isInsideOuterSuspenseOutsideSlot()) {
608
+ markDynamicAccess("slot-revalidate-0");
609
+ } else {
610
+ try {
611
+ getContext()?._markDynamic?.();
612
+ } catch (e) {}
613
+ }
614
+ }
615
+
554
616
  if (!storage || isNoCache) {
555
- const childElement = typeof children === "function" ? await children() : children;
556
- const directContent = await asyncRenderJSXToClientJSX(childElement);
617
+ const directContent = await runSlotScope(async () => {
618
+ const childElement = typeof children === "function" ? await children() : children;
619
+ return await asyncRenderJSXToClientJSX(childElement);
620
+ });
557
621
  commitSlotTags(slotTagsToCommit);
558
622
  return wrapWithBoundary(directContent, true);
559
623
  }
@@ -567,9 +631,9 @@ async function DinouCacheSlot(props) {
567
631
  // triggers PPR postpone.
568
632
  if (
569
633
  isPprBuildActive() &&
570
- isInsideSuspense() &&
634
+ isInsideOuterSuspenseOutsideSlot() &&
571
635
  cached &&
572
- !cached.metadata?.inStaticShell
636
+ !cached.metadata?.inStaticSuspense
573
637
  ) {
574
638
  cached = null;
575
639
  }
@@ -585,7 +649,16 @@ async function DinouCacheSlot(props) {
585
649
  ? meta.revalidate
586
650
  : undefined;
587
651
 
588
- if (revalidateSeconds === 0) {
652
+ if (typeof revalidateSeconds === "number" && revalidateSeconds < 1) {
653
+ if (!isSlotDiscoveryActive()) {
654
+ if (isPprBuildActive() && isInsideOuterSuspenseOutsideSlot()) {
655
+ markDynamicAccess("slot-revalidate-0");
656
+ } else {
657
+ try {
658
+ getContext()?._markDynamic?.();
659
+ } catch (e) {}
660
+ }
661
+ }
589
662
  const childElement = typeof children === "function" ? await children() : children;
590
663
  const directContent = await asyncRenderJSXToClientJSX(childElement);
591
664
  commitSlotTags(slotTagsToCommit);
@@ -597,7 +670,41 @@ async function DinouCacheSlot(props) {
597
670
  revalidateSeconds > 0 &&
598
671
  now > generatedAt + revalidateSeconds * 1000;
599
672
 
600
- if (!isExpired) {
673
+ const serveStaleWhileRevalidate =
674
+ isExpired &&
675
+ Boolean(meta.inStaticShell) &&
676
+ !isRevalidationActive() &&
677
+ !isPprBuildActive() &&
678
+ !getContext()?.platformContext?.isSSG;
679
+
680
+ if (
681
+ serveStaleWhileRevalidate &&
682
+ !getContext()?._isPprRuntimeResume &&
683
+ !backgroundRevalidations.has(storageKey) &&
684
+ !inflightSlotRenders.has(storageKey)
685
+ ) {
686
+ backgroundRevalidations.add(storageKey);
687
+ const reqContext = getContext();
688
+ const currentPath = reqContext?.req?.path;
689
+ const bgPromise = (async () => {
690
+ try {
691
+ await getSlotJSX(slotId, { fresh: true, currentPath });
692
+ } catch (e) {
693
+ console.error(
694
+ `[DinouCacheSlot] Background revalidation failed for slot "${slotId}":`,
695
+ e
696
+ );
697
+ } finally {
698
+ backgroundRevalidations.delete(storageKey);
699
+ }
700
+ })();
701
+ const ctx = reqContext?.platformContext?.ctx;
702
+ if (ctx && typeof ctx.waitUntil === "function") {
703
+ ctx.waitUntil(bgPromise);
704
+ }
705
+ }
706
+
707
+ if (!isExpired || serveStaleWhileRevalidate) {
601
708
  try {
602
709
  const restored = deserializeJSX(cached.content);
603
710
  const withRefreshedNested = await refreshNestedSlotsInTree(restored, slotId);
@@ -612,16 +719,22 @@ async function DinouCacheSlot(props) {
612
719
  try {
613
720
  const deduped = await inflightSlotRenders.get(storageKey);
614
721
  commitSlotTags(slotTagsToCommit);
615
- return wrapWithBoundary(deduped, true);
722
+ return wrapWithBoundary(deduped, !isPprBuildActive());
616
723
  } catch (e) {}
617
724
  }
618
725
 
619
- const inPprSuspense = isPprBuildActive() && isInsideSuspense();
620
- const isPprShellBuild = isPprBuildActive();
726
+ const inPprSuspense = isPprBuildActive() && isInsideOuterSuspenseOutsideSlot();
727
+ const isPprShellBuild =
728
+ isPprBuildActive() ||
729
+ Boolean(getContext()?.platformContext?.isSSG) ||
730
+ isRevalidationActive() ||
731
+ !getContext()?._isPprRuntimeResume;
621
732
 
622
733
  const renderPromise = (async () => {
623
- const childElement = typeof children === "function" ? await children() : children;
624
- const resolved = await asyncRenderJSXToClientJSX(childElement);
734
+ const resolved = await runInCachedSlot(async () => {
735
+ const childElement = typeof children === "function" ? await children() : children;
736
+ return await asyncRenderJSXToClientJSX(childElement);
737
+ });
625
738
  const serialized = serializeJSX(resolved);
626
739
 
627
740
  const slotMeta = {
@@ -630,6 +743,7 @@ async function DinouCacheSlot(props) {
630
743
  generatedAt: Date.now(),
631
744
  slotId,
632
745
  inStaticShell: Boolean(isPprShellBuild || cached?.metadata?.inStaticShell),
746
+ inStaticSuspense: Boolean(inPprSuspense || cached?.metadata?.inStaticSuspense),
633
747
  };
634
748
 
635
749
  const persistSlot = async () => {
@@ -660,6 +774,7 @@ async function DinouCacheSlot(props) {
660
774
  inflightSlotRenders.delete(storageKey);
661
775
  }
662
776
  }
777
+ DinouCacheSlot.$$dinouCacheSlot = true;
663
778
 
664
779
  /**
665
780
  * Resolves a slot ID or tag to its canonical slotId using slotRegistry or storage metadata.
@@ -757,7 +872,17 @@ async function getSlotJSX(slotId, options = {}) {
757
872
  revalidateSeconds > 0 &&
758
873
  now > generatedAt + revalidateSeconds * 1000);
759
874
 
760
- if (!isExpired && !options.fresh) {
875
+ const serveStaleWhileRevalidate =
876
+ isExpired &&
877
+ !isNoCache &&
878
+ !options.fresh &&
879
+ Boolean(options.skipHostRevalidate) &&
880
+ Boolean(meta.inStaticShell) &&
881
+ !isRevalidationActive() &&
882
+ !isPprBuildActive() &&
883
+ !getContext()?.platformContext?.isSSG;
884
+
885
+ if ((!isExpired && !options.fresh) || serveStaleWhileRevalidate) {
761
886
  try {
762
887
  const restored = deserializeJSX(cached.content);
763
888
  return await refreshNestedSlotsInTree(restored, targetId, options);
@@ -800,7 +925,7 @@ async function getSlotJSX(slotId, options = {}) {
800
925
  try {
801
926
  const isNotFound = { value: false };
802
927
  await runWithPprContext({ isPpr: true }, async () => {
803
- await slotDiscoveryStorage.run({ active: true }, async () => {
928
+ await runInSlotDiscovery(async () => {
804
929
  const pageJsx = await getJSX(options.currentPath, {}, isNotFound, false, false, {
805
930
  segment: "page",
806
931
  });
@@ -881,6 +1006,7 @@ async function getSlotJSX(slotId, options = {}) {
881
1006
  generatedAt: Date.now(),
882
1007
  slotId: targetId,
883
1008
  inStaticShell: Boolean(cached?.metadata?.inStaticShell),
1009
+ inStaticSuspense: Boolean(cached?.metadata?.inStaticSuspense),
884
1010
  });
885
1011
  }
886
1012
  if (options.fresh && isLatestGen()) {
@@ -918,13 +1044,7 @@ async function getSlotJSX(slotId, options = {}) {
918
1044
  ...(Array.isArray(entry.tags) ? entry.tags : []),
919
1045
  ]);
920
1046
  const metaKey = cleanRouteKey ? `${cleanRouteKey}/metadata.json` : "metadata.json";
921
- const metaItem = await storage.get(metaKey);
922
- let pageMeta = metaItem?.metadata;
923
- if (!pageMeta && metaItem?.content) {
924
- try {
925
- pageMeta = JSON.parse(metaItem.content);
926
- } catch (e) {}
927
- }
1047
+ const pageMeta = await readMetaFromStorageOrAssets(storage, metaKey);
928
1048
  if (
929
1049
  pageMeta &&
930
1050
  Array.isArray(pageMeta.slotTags) &&
@@ -942,13 +1062,7 @@ async function getSlotJSX(slotId, options = {}) {
942
1062
  }
943
1063
  for (const lKey of candidateLayoutKeys) {
944
1064
  const lMetaKey = lKey ? `${lKey}/layout.metadata.json` : "layout.metadata.json";
945
- const lItem = await storage.get(lMetaKey);
946
- let lMeta = lItem?.metadata;
947
- if (!lMeta && lItem?.content) {
948
- try {
949
- lMeta = JSON.parse(lItem.content);
950
- } catch (e) {}
951
- }
1065
+ const lMeta = await readMetaFromStorageOrAssets(storage, lMetaKey);
952
1066
  if (
953
1067
  lMeta &&
954
1068
  Array.isArray(lMeta.slotTags) &&