dinou 9.2.0 → 9.3.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/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
 
8
+ ## [9.3.0] - 2026-11-07
9
+
10
+ ### Added
11
+ - **Smart Cache-Aware `<Suspense>` Streaming for `<DinouCacheSlot>` in Dynamic SSR Routes**: Enabled non-blocking TTFB streaming on cache misses and zero-fallback inlining on cache hits whenever `<DinouCacheSlot>` is wrapped inside `<Suspense>` on a dynamic SSR route (`revalidate = 0` or routes accessing request-time `cookies`, `headers`, or `query` with `ppr = false`):
12
+ - **Non-Blocking TTFB on Cold Cache Misses & After `revalidateTag()` Purges**: When a `<DinouCacheSlot>` inside an outer `<Suspense>` boundary (`isInsideRuntimeSuspenseOutsideSlot()`) misses storage cache (1st request, after `revalidateTag()`, or `revalidate={0}`), it immediately flushes the dynamic page shell and the `<Suspense>` `fallback` via `<DinouDeferredSlotStream>` without blocking `getJSX`, streaming the resolved widget (`$RC(...)`) in the same HTTP response and persisting `slot.json` for subsequent requests.
13
+ - **Zero Fallback Flash on Warm Cache Hits & Expired TTLs (Background SWR)**: When `slot.json` is present in storage, `DinouCacheSlot` deserializes and inlines the cached subtree synchronously during `getJSX` across both `development` and `production` (`containsCacheSlot`), never emitting the `<Suspense>` `fallback` on warm hits or during non-blocking background SWR revalidations (`inStaticShell: true`).
14
+ - **Awaitable `refreshSlot(slotId, options): Promise<void>` Client API**: Updated `refreshSlot` and `useRouter().refreshSlot` across ESM, Rollup, and Webpack client runtimes (`client.jsx`, `client-webpack.jsx`, `navigation.js`, `slot.js`, and `index.d.ts`) to return a `Promise<void>` that settles once all matching `<DinouCacheSlotBoundary>` and unmounted slot refreshes complete, enabling `await refreshSlot(...)` inside `React.useTransition()` for non-destructive loading indicators while reconciling slot content in-place without unmounting to the outer `<Suspense>` `fallback`.
15
+
8
16
  ## [9.2.0] - 2026-11-06
9
17
 
10
18
  ### Added
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Dinou
2
2
 
3
3
  [![Documentation](https://img.shields.io/badge/docs-dinou.dev-blue?style=flat-square)](https://dinou.dev)
4
- [![Version](https://img.shields.io/badge/version-9.2.0-orange?style=flat-square)](https://www.npmjs.com/package/dinou)
4
+ [![Version](https://img.shields.io/badge/version-9.3.0-orange?style=flat-square)](https://www.npmjs.com/package/dinou)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style=flat-square)](./LICENSE.md)
6
6
 
7
7
  **The Ejectable Full-Stack React 19 Framework.**
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.2.0")
17
+ .version("9.3.0")
18
18
  .option("-u, --unvendorized", "Run with standard node_modules dependencies instead of pre-bundled vendor packages");
19
19
 
20
20
  const isUnvendorizedRequested = () =>
@@ -14,6 +14,7 @@ import {
14
14
  isPprBuildActive,
15
15
  isInsideSuspense,
16
16
  isInsideOuterSuspenseOutsideSlot,
17
+ isInsideRuntimeSuspenseOutsideSlot,
17
18
  deferPprSuspenseEffect,
18
19
  runWithPprContext,
19
20
  isInsideLayoutSegment,
@@ -503,6 +504,15 @@ async function refreshNestedSlotsInTree(node, currentSlotId, options = {}) {
503
504
  return node;
504
505
  }
505
506
 
507
+ async function DinouDeferredSlotStream({ promise }) {
508
+ const [res] = await Promise.all([
509
+ promise,
510
+ new Promise((r) => setTimeout(r, 0)),
511
+ ]);
512
+ return res;
513
+ }
514
+ DinouDeferredSlotStream.$$dinouDeferredSuspenseStream = true;
515
+
506
516
  /**
507
517
  * DinouCacheSlot component.
508
518
  *
@@ -516,6 +526,19 @@ async function refreshNestedSlotsInTree(node, currentSlotId, options = {}) {
516
526
  async function DinouCacheSlot(props) {
517
527
  const { id, tag, tags, revalidate, children } = props || {};
518
528
  const isNoCache = typeof revalidate === "number" && revalidate < 1;
529
+ const reqCtxInitial = getContext();
530
+ const shouldStreamSlotInSuspense =
531
+ isInsideRuntimeSuspenseOutsideSlot() &&
532
+ !isPprBuildActive() &&
533
+ !reqCtxInitial?.platformContext?.isSSG &&
534
+ !isRevalidationActive() &&
535
+ !isSlotDiscoveryActive() &&
536
+ !reqCtxInitial?._isPprRuntimeResume &&
537
+ (Boolean(reqCtxInitial?._dynamicState?.value) ||
538
+ isNoCache ||
539
+ Object.keys(reqCtxInitial?.req?.query || {}).length > 0 ||
540
+ process.env.DINOU_DEV === "true" ||
541
+ process.env.NODE_ENV !== "production");
519
542
 
520
543
  const slotId = id || tag || (Array.isArray(tags) ? tags[0] : null);
521
544
  if (!slotId) {
@@ -529,10 +552,17 @@ async function DinouCacheSlot(props) {
529
552
  }
530
553
  }
531
554
  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
- });
555
+ const computeAnon = () =>
556
+ runScope(async () => {
557
+ const childElement = typeof children === "function" ? await children() : children;
558
+ return await asyncRenderJSXToClientJSX(childElement);
559
+ });
560
+ if (shouldStreamSlotInSuspense) {
561
+ const anonPromise = computeAnon();
562
+ anonPromise.catch(() => {});
563
+ return React.createElement(DinouDeferredSlotStream, { promise: anonPromise });
564
+ }
565
+ return await computeAnon();
536
566
  }
537
567
 
538
568
  const allTags = Array.isArray(tags)
@@ -621,6 +651,20 @@ async function DinouCacheSlot(props) {
621
651
  }
622
652
 
623
653
  if (!storage || isNoCache) {
654
+ if (shouldStreamSlotInSuspense) {
655
+ commitSlotTags(slotTagsToCommit);
656
+ const noCacheStreamPromise = (async () => {
657
+ const directContent = await runSlotScope(async () => {
658
+ const childElement = typeof children === "function" ? await children() : children;
659
+ return await asyncRenderJSXToClientJSX(childElement);
660
+ });
661
+ return await asyncRenderJSXToClientJSX(wrapWithBoundary(directContent, true));
662
+ })();
663
+ noCacheStreamPromise.catch(() => {});
664
+ return React.createElement(DinouDeferredSlotStream, {
665
+ promise: noCacheStreamPromise,
666
+ });
667
+ }
624
668
  const directContent = await runSlotScope(async () => {
625
669
  const childElement = typeof children === "function" ? await children() : children;
626
670
  return await asyncRenderJSXToClientJSX(childElement);
@@ -666,6 +710,20 @@ async function DinouCacheSlot(props) {
666
710
  } catch (e) {}
667
711
  }
668
712
  }
713
+ if (shouldStreamSlotInSuspense) {
714
+ commitSlotTags(slotTagsToCommit);
715
+ const noCacheStreamPromise = (async () => {
716
+ const directContent = await runSlotScope(async () => {
717
+ const childElement = typeof children === "function" ? await children() : children;
718
+ return await asyncRenderJSXToClientJSX(childElement);
719
+ });
720
+ return await asyncRenderJSXToClientJSX(wrapWithBoundary(directContent, true));
721
+ })();
722
+ noCacheStreamPromise.catch(() => {});
723
+ return React.createElement(DinouDeferredSlotStream, {
724
+ promise: noCacheStreamPromise,
725
+ });
726
+ }
669
727
  const directContent = await runSlotScope(async () => {
670
728
  const childElement = typeof children === "function" ? await children() : children;
671
729
  return await asyncRenderJSXToClientJSX(childElement);
@@ -725,8 +783,19 @@ async function DinouCacheSlot(props) {
725
783
 
726
784
  // 2. Cache MISS or expired TTL: Deduplicate synchronous render
727
785
  if (inflightSlotRenders.has(storageKey)) {
786
+ const existingPromise = inflightSlotRenders.get(storageKey);
787
+ if (shouldStreamSlotInSuspense) {
788
+ commitSlotTags(slotTagsToCommit);
789
+ const dedupedStreamPromise = existingPromise.then(async (deduped) => {
790
+ return await asyncRenderJSXToClientJSX(wrapWithBoundary(deduped, true));
791
+ });
792
+ dedupedStreamPromise.catch(() => {});
793
+ return React.createElement(DinouDeferredSlotStream, {
794
+ promise: dedupedStreamPromise,
795
+ });
796
+ }
728
797
  try {
729
- const deduped = await inflightSlotRenders.get(storageKey);
798
+ const deduped = await existingPromise;
730
799
  commitSlotTags(slotTagsToCommit);
731
800
  return wrapWithBoundary(deduped, !isPprBuildActive());
732
801
  } catch (e) {}
@@ -778,6 +847,21 @@ async function DinouCacheSlot(props) {
778
847
  })();
779
848
 
780
849
  inflightSlotRenders.set(storageKey, renderPromise);
850
+ if (shouldStreamSlotInSuspense) {
851
+ commitSlotTags(slotTagsToCommit);
852
+ const streamPromise = (async () => {
853
+ try {
854
+ const fresh = await renderPromise;
855
+ return await asyncRenderJSXToClientJSX(wrapWithBoundary(fresh, true));
856
+ } finally {
857
+ inflightSlotRenders.delete(storageKey);
858
+ }
859
+ })();
860
+ streamPromise.catch(() => {});
861
+ return React.createElement(DinouDeferredSlotStream, {
862
+ promise: streamPromise,
863
+ });
864
+ }
781
865
  try {
782
866
  const fresh = await renderPromise;
783
867
  commitSlotTags(slotTagsToCommit);
@@ -313,10 +313,15 @@ const fetchSlotRSC = (slotId, options = {}) => {
313
313
 
314
314
  export const refreshSlot = (slotId, options) => {
315
315
  if (typeof window !== "undefined") {
316
+ const promises = [];
316
317
  window.dispatchEvent(
317
- new CustomEvent("dinou:refresh-slot", { detail: { id: slotId, options } })
318
+ new CustomEvent("dinou:refresh-slot", {
319
+ detail: { id: slotId, options, promises },
320
+ })
318
321
  );
322
+ return Promise.all(promises).then(() => undefined);
319
323
  }
324
+ return Promise.resolve();
320
325
  };
321
326
 
322
327
  if (typeof globalThis !== "undefined") {
@@ -313,10 +313,15 @@ const fetchSlotRSC = (slotId, options = {}) => {
313
313
 
314
314
  export const refreshSlot = (slotId, options) => {
315
315
  if (typeof window !== "undefined") {
316
+ const promises = [];
316
317
  window.dispatchEvent(
317
- new CustomEvent("dinou:refresh-slot", { detail: { id: slotId, options } })
318
+ new CustomEvent("dinou:refresh-slot", {
319
+ detail: { id: slotId, options, promises },
320
+ })
318
321
  );
322
+ return Promise.all(promises).then(() => undefined);
319
323
  }
324
+ return Promise.resolve();
320
325
  };
321
326
 
322
327
  if (typeof globalThis !== "undefined") {
@@ -120,7 +120,7 @@ if (typeof globalThis !== "undefined" && globalThis.__DINOU_CONFIG__) {
120
120
  function copyCustomContextProperties(source, target) {
121
121
  if (!source || !target) return;
122
122
  for (const key of Object.keys(source)) {
123
- if (!["req", "res", "env", "ctx", "platformContext", "_markDynamic"].includes(key)) {
123
+ if (!["req", "res", "env", "ctx", "platformContext", "_markDynamic", "_dynamicState"].includes(key)) {
124
124
  target[key] = source[key];
125
125
  }
126
126
  }
@@ -887,6 +887,7 @@ function createRequestContext(simReq, resBridge, platformContext = {}, dynamicSt
887
887
  ctx: platformContext.ctx || null,
888
888
  platformContext,
889
889
  _markDynamic: markDynamic,
890
+ _dynamicState: dynamicState,
890
891
  };
891
892
 
892
893
  if (dinouConfig.plugins && Array.isArray(dinouConfig.plugins)) {
@@ -63,6 +63,7 @@ export function useRouter() {
63
63
  back: () => { },
64
64
  forward: () => { },
65
65
  refresh: (options) => { },
66
+ refreshSlot: (slotId, options) => Promise.resolve(),
66
67
  };
67
68
  }
68
69
 
@@ -102,13 +103,17 @@ export function useRouter() {
102
103
  export function refreshSlot(slotId, options) {
103
104
  if (typeof window !== "undefined") {
104
105
  if (typeof window.__DINOU_REFRESH_SLOT__ === "function") {
105
- window.__DINOU_REFRESH_SLOT__(slotId, options);
106
- } else {
107
- window.dispatchEvent(
108
- new CustomEvent("dinou:refresh-slot", { detail: { id: slotId, options } })
109
- );
106
+ return window.__DINOU_REFRESH_SLOT__(slotId, options);
110
107
  }
108
+ const promises = [];
109
+ window.dispatchEvent(
110
+ new CustomEvent("dinou:refresh-slot", {
111
+ detail: { id: slotId, options, promises },
112
+ })
113
+ );
114
+ return Promise.all(promises).then(() => undefined);
111
115
  }
116
+ return Promise.resolve();
112
117
  }
113
118
 
114
119
  const DINOU_CONTEXT_KEY = Symbol.for("dinou.request.context.storage");
@@ -27,6 +27,10 @@ export function runInRuntimeStaticSuspense(callback) {
27
27
 
28
28
  export function runInRuntimeDynamicHole(callback, holeId = null) {
29
29
  const prev = runtimeStaticSuspenseStorage.getStore();
30
+ const slotDepthAtSuspense =
31
+ prev && typeof prev.slotDepthAtSuspense === "number"
32
+ ? prev.slotDepthAtSuspense
33
+ : cachedSlotStorage.getStore()?.depth || 0;
30
34
  return runtimeStaticSuspenseStorage.run(
31
35
  {
32
36
  active: false,
@@ -34,6 +38,7 @@ export function runInRuntimeDynamicHole(callback, holeId = null) {
34
38
  holeId: holeId || prev?.holeId || null,
35
39
  idCount: 0,
36
40
  childHoleCount: 0,
41
+ slotDepthAtSuspense,
37
42
  },
38
43
  callback
39
44
  );
@@ -44,6 +49,16 @@ export function getActiveRuntimeDynamicHoleStore() {
44
49
  return store && store.holeId ? store : null;
45
50
  }
46
51
 
52
+ export function isInsideRuntimeSuspenseOutsideSlot() {
53
+ const currentSlotDepth = cachedSlotStorage.getStore()?.depth || 0;
54
+ if (currentSlotDepth > 0) return false;
55
+ const holeStore = getActiveRuntimeDynamicHoleStore();
56
+ if (holeStore && (holeStore.slotDepthAtSuspense || 0) === 0) {
57
+ return true;
58
+ }
59
+ return isInsideOuterSuspenseOutsideSlot();
60
+ }
61
+
47
62
  export function isRuntimeStaticSuspenseActive() {
48
63
  const store = runtimeStaticSuspenseStorage.getStore();
49
64
  return Boolean(store && store.active && store.depth > 0);
@@ -363,6 +363,18 @@ function isCacheSlotComponent(fn) {
363
363
  return Boolean(fn.$$dinouCacheSlot || fn.name === "DinouCacheSlot");
364
364
  }
365
365
 
366
+ function containsCacheSlot(node) {
367
+ if (!node || typeof node !== "object") return false;
368
+ if (Array.isArray(node)) {
369
+ return node.some(containsCacheSlot);
370
+ }
371
+ if (node.$$typeof === Symbol.for("react.transitional.element")) {
372
+ if (isCacheSlotComponent(node.type)) return true;
373
+ return containsCacheSlot(node.props?.children);
374
+ }
375
+ return false;
376
+ }
377
+
366
378
  async function invokeServerComponentInPpr(fn, callFn) {
367
379
  while (true) {
368
380
  resetComponentNoDynamicFlag();
@@ -624,7 +636,8 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
624
636
  Boolean(getPprStore()) ||
625
637
  Boolean(getActiveRuntimeDynamicHoleStore()) ||
626
638
  Boolean(getContext()?.platformContext?.isSSG) ||
627
- process.env.NODE_ENV === "production";
639
+ process.env.NODE_ENV === "production" ||
640
+ containsCacheSlot(jsx.props?.children);
628
641
  if (shouldEagerlyResolveSuspense) {
629
642
  return await runInSuspense(async (holeId) => {
630
643
  const renderedChildren = await runInRuntimeDynamicHole(
@@ -689,6 +702,8 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
689
702
  key ?? jsx.key,
690
703
  Component
691
704
  );
705
+ } else if (Component.$$dinouDeferredSuspenseStream) {
706
+ return jsx;
692
707
  } else {
693
708
  // Server component: execute and process
694
709
  const returnedJsx = await invokeServerComponentInPpr(Component, () =>
@@ -313,7 +313,7 @@ if (
313
313
  entry.pendingPromise = promise;
314
314
  entry.pendingReqId = reqId;
315
315
  const baseRef = entry.baseChildren;
316
- promise.then(
316
+ const settledPromise = promise.then(
317
317
  (resolved) => {
318
318
  if (entry.latestReqId !== reqId) {
319
319
  return;
@@ -335,6 +335,9 @@ if (
335
335
  }
336
336
  }
337
337
  );
338
+ if (Array.isArray(e?.detail?.promises)) {
339
+ e.detail.promises.push(settledPromise);
340
+ }
338
341
  }
339
342
  }
340
343
  }
@@ -459,7 +462,7 @@ export function DinouCacheSlotBoundary({ id, tags, children }) {
459
462
  curEntry.pendingPromise = promise;
460
463
  curEntry.pendingReqId = reqId;
461
464
  }
462
- promise.then(
465
+ const settledPromise = promise.then(
463
466
  (resolved) => {
464
467
  if (curEntry && curEntry.latestReqId !== reqId) {
465
468
  return;
@@ -476,6 +479,9 @@ export function DinouCacheSlotBoundary({ id, tags, children }) {
476
479
  console.error(`[Dinou] Failed to refresh slot "${id}":`, err);
477
480
  }
478
481
  );
482
+ if (Array.isArray(e?.detail?.promises)) {
483
+ e.detail.promises.push(settledPromise);
484
+ }
479
485
  } else if (promise) {
480
486
  if (curEntry) {
481
487
  curEntry.pendingPromise = null;
package/dinou/index.d.ts CHANGED
@@ -588,15 +588,16 @@ export declare function useRouter(): {
588
588
  * @param slotId - The slot identifier or tag.
589
589
  * @param options - Optional configuration ({ fresh?: boolean }).
590
590
  */
591
- refreshSlot: (slotId: string, options?: { fresh?: boolean }) => void;
591
+ refreshSlot: (slotId: string, options?: { fresh?: boolean }) => Promise<void>;
592
592
  };
593
593
 
594
594
  /**
595
595
  * Programmatically refreshes a specific DinouCacheSlot in the browser without reloading the page.
596
+ * Returns a Promise that resolves once matching slot refreshes have settled.
596
597
  * @param slotId - The slot identifier or tag to refresh.
597
598
  * @param options - Optional configuration ({ fresh?: boolean }).
598
599
  */
599
- export declare function refreshSlot(slotId: string, options?: { fresh?: boolean }): void;
600
+ export declare function refreshSlot(slotId: string, options?: { fresh?: boolean }): Promise<void>;
600
601
 
601
602
  /**
602
603
  * A Client Component hook that returns true if a navigation (SPA transition) is currently in progress.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinou-ejected",
3
- "version": "9.2.0",
3
+ "version": "9.3.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "bin": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinou",
3
- "version": "9.2.0",
3
+ "version": "9.3.0",
4
4
  "description": "Full-stack React 19 framework with native RSC, Server Functions, progressive streaming, and zero vendor lock-in.",
5
5
  "type": "module",
6
6
  "main": "./dinou/index.js",