dinou 9.1.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 +21 -0
- package/README.md +1 -1
- package/dinou/cli.js +1 -1
- package/dinou/core/cache-slot.js +117 -21
- package/dinou/core/client-webpack.jsx +6 -1
- package/dinou/core/client.jsx +6 -1
- package/dinou/core/get-jsx.js +75 -7
- package/dinou/core/handler.js +7 -3
- package/dinou/core/navigation.js +10 -5
- package/dinou/core/ppr-context.js +137 -10
- package/dinou/core/ppr-runtime.js +68 -11
- package/dinou/core/render-jsx-to-client-jsx.js +531 -55
- package/dinou/core/rsc-renderer.js +3 -0
- package/dinou/core/slot.js +8 -2
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +242 -242
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +253 -253
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +209 -209
- package/dinou/index.d.ts +3 -2
- package/dinou/node/dev.js +2866 -2853
- package/dinou/package.json +1 -1
- package/dinou/rollup/react-refresh/esm-hmr/client.js +220 -220
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +182 -182
- package/dinou/server.d.ts +29 -29
- package/dinou/server.js +1 -1
- package/dinou/webpack/loaders/server-functions-loader.js +101 -101
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,27 @@ 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
|
+
|
|
16
|
+
## [9.2.0] - 2026-11-06
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- **React 19 Synchronous Server Component `useId()` & Stateless Hooks Support**: Implemented a deterministic Server Hooks dispatcher (`DinouServerHooksDispatcher`) supporting React 19's official synchronous Server Component hooks (`useId`, `use`, `useMemo`, `useCallback`, `useDebugValue`, and the React Compiler's `useMemoCache`) across all rendering modes (`dev`, Node.js AOT Dual-Bundle, Bun, Deno, Cloudflare Workers, and Netlify):
|
|
20
|
+
- **5-Tier Hierarchical Scoped ID Engine (`useServerId`)**: Guarantees 100% hydration parity between full-document SSR (`GET /path`) and segmented RSC endpoints (`GET /____rsc_layout____/path`, `GET /____rsc_page____/path`, and `GET /____rsc_slot____/:id`) by scoping generated IDs to their exact execution boundary: `<DinouCacheSlot>` (`_slot_<id>_dS_<N>_`), `<Suspense>` / PPR Hole (`_hole_<id>_dS_<N>_`), Page segment (`_page_dS_<N>_`), Layout / Parallel `@slot` segment (`_layout_dS_<N>_`), and a request-level fallback (`_dS_<N>_`).
|
|
21
|
+
- **Dual Dispatcher Interception**: Patched React's internal dispatcher setter (`__SERVER_INTERNALS` / `__CLIENT_INTERNALS`) so both Dinou's pre-evaluation pass (`asyncRenderJSXToClientJSX`) and `react-server-dom-webpack`'s live Flight streaming pass route `useId()` and `use()` through Dinou's context-aware dispatcher.
|
|
22
|
+
- **Sibling `<Suspense>` Race-Condition Immunity**: Enforces deterministic tree-order JSX traversal (`for...of`), pre-allocates `<Suspense>` boundary IDs (`layout-hole-N`, `ppr-hole-N`, `ppr-hole-N-M`), and isolates their internal `useId()` counters via `runInRuntimeDynamicHole` (evaluating eagerly during SSG/PPR/production so `ppr = false` static routes resolve into static HTML, and streaming via `<DinouSuspenseHoleBoundary>` in `dev`), preventing timer resolution order or Flight `MAX_ROW_SIZE` chunk deferrals from shifting sibling IDs.
|
|
23
|
+
- **`React.use(pendingPromise)` Replay Counter Rollback**: Snapshots and restores active scope ID counters whenever a synchronous Server Component suspends on a pending thenable via `React.use()`, ensuring re-invocations produce identical IDs without gaps.
|
|
24
|
+
- **`React.memo` & `React.forwardRef` Server Component Unwrapping**: Added support for stateless server hooks inside `React.memo`, `React.forwardRef`, and nested `React.memo(React.forwardRef(...))` Server Components across both standard RSC rendering and PPR dynamic hole streaming/splicing.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- **Single-Pass Layout & Parallel `@slot` Evaluation with Error-Isolation Rollback**: Optimized `getJSX` to evaluate each `Layout` and parallel `@slot` once inside `runInLayoutSegment` using a structural children placeholder (`createLayoutChildrenPlaceholder` / `replaceLayoutChildrenPlaceholder`), rolling back segment ID and hole counters automatically if a nested layout or `@slot` throws and falls back to `error.tsx`.
|
|
28
|
+
|
|
8
29
|
## [9.1.0] - 2026-11-05
|
|
9
30
|
|
|
10
31
|
### Added
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Dinou
|
|
2
2
|
|
|
3
3
|
[](https://dinou.dev)
|
|
4
|
-
[](https://www.npmjs.com/package/dinou)
|
|
5
5
|
[](./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.
|
|
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 = () =>
|
package/dinou/core/cache-slot.js
CHANGED
|
@@ -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,
|
|
@@ -304,10 +305,10 @@ function recordSlotTagsOnContext(
|
|
|
304
305
|
for (const t of tags) {
|
|
305
306
|
if (!t) continue;
|
|
306
307
|
reqContext._slotTags.add(t);
|
|
307
|
-
if (
|
|
308
|
-
reqContext._layoutSlotTags.add(t);
|
|
309
|
-
} else if (inPage) {
|
|
308
|
+
if (inPage) {
|
|
310
309
|
reqContext._pageSlotTags.add(t);
|
|
310
|
+
} else if (inLayout) {
|
|
311
|
+
reqContext._layoutSlotTags.add(t);
|
|
311
312
|
} else if (!reqContext._layoutSlotTags.has(t)) {
|
|
312
313
|
reqContext._pageSlotTags.add(t);
|
|
313
314
|
}
|
|
@@ -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
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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)
|
|
@@ -544,7 +574,8 @@ async function DinouCacheSlot(props) {
|
|
|
544
574
|
|
|
545
575
|
const storageKey = `slots/${slotId}/slot.json`;
|
|
546
576
|
const storage = getStorageAdapter();
|
|
547
|
-
const runSlotScope =
|
|
577
|
+
const runSlotScope = (fn) =>
|
|
578
|
+
runInCachedSlot(fn, { cached: !isNoCache, slotId });
|
|
548
579
|
|
|
549
580
|
function wrapWithBoundary(content, alreadyRendered = false) {
|
|
550
581
|
const Boundary = getCacheSlotBoundary();
|
|
@@ -583,8 +614,10 @@ async function DinouCacheSlot(props) {
|
|
|
583
614
|
discoveringSlots.add(slotId);
|
|
584
615
|
try {
|
|
585
616
|
await runInSlotDiscovery(async () => {
|
|
586
|
-
|
|
587
|
-
|
|
617
|
+
await runSlotScope(async () => {
|
|
618
|
+
const childElement = typeof children === "function" ? await children() : children;
|
|
619
|
+
await asyncRenderJSXToClientJSX(childElement);
|
|
620
|
+
});
|
|
588
621
|
});
|
|
589
622
|
} catch (e) {
|
|
590
623
|
} finally {
|
|
@@ -596,11 +629,15 @@ async function DinouCacheSlot(props) {
|
|
|
596
629
|
});
|
|
597
630
|
|
|
598
631
|
// When running inside a nested slot discovery pass, recursively discover any child slots
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if (
|
|
602
|
-
|
|
632
|
+
// and short-circuit so discovery passes never overwrite storage cache with discovery renders.
|
|
633
|
+
if (isSlotDiscoveryActive()) {
|
|
634
|
+
if (!discoveringSlots.has(slotId)) {
|
|
635
|
+
const ownEntry = slotRegistry.get(slotId);
|
|
636
|
+
if (ownEntry && typeof ownEntry.discover === "function") {
|
|
637
|
+
await ownEntry.discover();
|
|
638
|
+
}
|
|
603
639
|
}
|
|
640
|
+
return null;
|
|
604
641
|
}
|
|
605
642
|
|
|
606
643
|
if (isNoCache && !isSlotDiscoveryActive()) {
|
|
@@ -614,6 +651,20 @@ async function DinouCacheSlot(props) {
|
|
|
614
651
|
}
|
|
615
652
|
|
|
616
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
|
+
}
|
|
617
668
|
const directContent = await runSlotScope(async () => {
|
|
618
669
|
const childElement = typeof children === "function" ? await children() : children;
|
|
619
670
|
return await asyncRenderJSXToClientJSX(childElement);
|
|
@@ -659,8 +710,24 @@ async function DinouCacheSlot(props) {
|
|
|
659
710
|
} catch (e) {}
|
|
660
711
|
}
|
|
661
712
|
}
|
|
662
|
-
|
|
663
|
-
|
|
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
|
+
}
|
|
727
|
+
const directContent = await runSlotScope(async () => {
|
|
728
|
+
const childElement = typeof children === "function" ? await children() : children;
|
|
729
|
+
return await asyncRenderJSXToClientJSX(childElement);
|
|
730
|
+
});
|
|
664
731
|
commitSlotTags(slotTagsToCommit);
|
|
665
732
|
return wrapWithBoundary(directContent, true);
|
|
666
733
|
}
|
|
@@ -716,8 +783,19 @@ async function DinouCacheSlot(props) {
|
|
|
716
783
|
|
|
717
784
|
// 2. Cache MISS or expired TTL: Deduplicate synchronous render
|
|
718
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
|
+
}
|
|
719
797
|
try {
|
|
720
|
-
const deduped = await
|
|
798
|
+
const deduped = await existingPromise;
|
|
721
799
|
commitSlotTags(slotTagsToCommit);
|
|
722
800
|
return wrapWithBoundary(deduped, !isPprBuildActive());
|
|
723
801
|
} catch (e) {}
|
|
@@ -731,10 +809,13 @@ async function DinouCacheSlot(props) {
|
|
|
731
809
|
!getContext()?._isPprRuntimeResume;
|
|
732
810
|
|
|
733
811
|
const renderPromise = (async () => {
|
|
734
|
-
const resolved = await runInCachedSlot(
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
812
|
+
const resolved = await runInCachedSlot(
|
|
813
|
+
async () => {
|
|
814
|
+
const childElement = typeof children === "function" ? await children() : children;
|
|
815
|
+
return await asyncRenderJSXToClientJSX(childElement);
|
|
816
|
+
},
|
|
817
|
+
{ cached: true, slotId }
|
|
818
|
+
);
|
|
738
819
|
const serialized = serializeJSX(resolved);
|
|
739
820
|
|
|
740
821
|
const slotMeta = {
|
|
@@ -766,6 +847,21 @@ async function DinouCacheSlot(props) {
|
|
|
766
847
|
})();
|
|
767
848
|
|
|
768
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
|
+
}
|
|
769
865
|
try {
|
|
770
866
|
const fresh = await renderPromise;
|
|
771
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", {
|
|
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") {
|
package/dinou/core/client.jsx
CHANGED
|
@@ -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", {
|
|
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") {
|
package/dinou/core/get-jsx.js
CHANGED
|
@@ -6,11 +6,23 @@ import {
|
|
|
6
6
|
getFilePathAndDynamicParams,
|
|
7
7
|
} from "./get-file-path-and-dynamic-params.js";
|
|
8
8
|
import importModule from "./import-module.js";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
asyncRenderJSXToClientJSX,
|
|
11
|
+
replaceLayoutChildrenPlaceholder,
|
|
12
|
+
} from "./render-jsx-to-client-jsx.js";
|
|
10
13
|
import { getLayoutProps } from "./layout-functions.js";
|
|
11
14
|
import { DinouPageSlot as RawDinouPageSlot } from "./slot.js";
|
|
12
15
|
import { getErrorJSX } from "./get-error-jsx.js";
|
|
13
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
markPageRootElement,
|
|
18
|
+
markLayoutRootElement,
|
|
19
|
+
createLayoutChildrenPlaceholder,
|
|
20
|
+
runInPageSegment,
|
|
21
|
+
runInLayoutSegment,
|
|
22
|
+
isPprBuildActive,
|
|
23
|
+
getPprStore,
|
|
24
|
+
} from "./ppr-context.js";
|
|
25
|
+
import { getContext } from "./request-context.js";
|
|
14
26
|
import { createRequire } from "node:module";
|
|
15
27
|
|
|
16
28
|
const require = createRequire(import.meta.url);
|
|
@@ -149,6 +161,14 @@ async function getJSX(
|
|
|
149
161
|
`no_layout_not_found`,
|
|
150
162
|
);
|
|
151
163
|
if (existsSync(noLayoutNotFoundPath)) {
|
|
164
|
+
if (
|
|
165
|
+
!isPprBuildActive() &&
|
|
166
|
+
!getPprStore() &&
|
|
167
|
+
!getContext()?._isPprRuntimeResume &&
|
|
168
|
+
!options?.skipLayoutProbe
|
|
169
|
+
) {
|
|
170
|
+
jsx = await runInPageSegment(() => asyncRenderJSXToClientJSX(jsx));
|
|
171
|
+
}
|
|
152
172
|
return jsx;
|
|
153
173
|
}
|
|
154
174
|
}
|
|
@@ -183,6 +203,15 @@ async function getJSX(
|
|
|
183
203
|
jsx = markPageRootElement(React.createElement(Page, props));
|
|
184
204
|
}
|
|
185
205
|
|
|
206
|
+
if (
|
|
207
|
+
!isPprBuildActive() &&
|
|
208
|
+
!getPprStore() &&
|
|
209
|
+
!getContext()?._isPprRuntimeResume &&
|
|
210
|
+
!options?.skipLayoutProbe
|
|
211
|
+
) {
|
|
212
|
+
jsx = await runInPageSegment(() => asyncRenderJSXToClientJSX(jsx));
|
|
213
|
+
}
|
|
214
|
+
|
|
186
215
|
// 2. Segmented handling for Page: If only the page is requested, return without layouts
|
|
187
216
|
if (options && options.segment === "page") {
|
|
188
217
|
return jsx;
|
|
@@ -217,6 +246,7 @@ async function getJSX(
|
|
|
217
246
|
|
|
218
247
|
if (layouts && Array.isArray(layouts)) {
|
|
219
248
|
let index = 0;
|
|
249
|
+
const layoutSegmentStore = { active: true, idCount: 0, holeCount: 0 };
|
|
220
250
|
for (const [layoutPath, dParams, slots] of layouts.reverse()) {
|
|
221
251
|
const layoutModule = await importModule(layoutPath);
|
|
222
252
|
const layoutFolderPath = path.dirname(layoutPath);
|
|
@@ -233,6 +263,8 @@ async function getJSX(
|
|
|
233
263
|
let updatedSlotElement;
|
|
234
264
|
const slotFilePath = slotValue?.slotPath || slotValue?.props?.__modulePath;
|
|
235
265
|
const slotParams = slotValue?.slotParams || slotValue?.props?.params || {};
|
|
266
|
+
const prevSlotIdCount = layoutSegmentStore.idCount;
|
|
267
|
+
const prevSlotHoleCount = layoutSegmentStore.holeCount;
|
|
236
268
|
try {
|
|
237
269
|
let elementToRender;
|
|
238
270
|
if (slotValue && slotValue.slotPath) {
|
|
@@ -246,9 +278,14 @@ async function getJSX(
|
|
|
246
278
|
} else {
|
|
247
279
|
elementToRender = slotValue;
|
|
248
280
|
}
|
|
249
|
-
await runInLayoutSegment(
|
|
250
|
-
|
|
281
|
+
const resolvedSlot = await runInLayoutSegment(
|
|
282
|
+
() => asyncRenderJSXToClientJSX(elementToRender),
|
|
283
|
+
layoutSegmentStore
|
|
284
|
+
);
|
|
285
|
+
updatedSlotElement = isPprBuildActive() ? elementToRender : resolvedSlot;
|
|
251
286
|
} catch (e) {
|
|
287
|
+
layoutSegmentStore.idCount = prevSlotIdCount;
|
|
288
|
+
layoutSegmentStore.holeCount = prevSlotHoleCount;
|
|
252
289
|
if (slotFilePath) {
|
|
253
290
|
const realSlotFolder = path.dirname(slotFilePath);
|
|
254
291
|
|
|
@@ -298,13 +335,44 @@ async function getJSX(
|
|
|
298
335
|
const layoutProps = await getLayoutProps(layoutPath, dParams);
|
|
299
336
|
let props = { params: dParams, ...updatedSlots, ...(layoutProps ?? {}) };
|
|
300
337
|
if (options?.skipLayoutProbe) {
|
|
301
|
-
jsx = React.createElement(Layout, props, jsx);
|
|
302
|
-
} else {
|
|
338
|
+
jsx = markLayoutRootElement(React.createElement(Layout, props, jsx));
|
|
339
|
+
} else if (isPprBuildActive()) {
|
|
303
340
|
try {
|
|
304
341
|
const testElement = React.createElement(Layout, props, null);
|
|
305
342
|
await runInLayoutSegment(() => asyncRenderJSXToClientJSX(testElement));
|
|
306
|
-
jsx = React.createElement(Layout, props, jsx);
|
|
343
|
+
jsx = markLayoutRootElement(React.createElement(Layout, props, jsx));
|
|
344
|
+
} catch (layoutErr) {
|
|
345
|
+
console.warn(
|
|
346
|
+
`[Dinou] Layout ${layoutPath} failed during render, isolating layout error:`,
|
|
347
|
+
layoutErr?.message || layoutErr
|
|
348
|
+
);
|
|
349
|
+
const serializedError = {
|
|
350
|
+
message: layoutErr.message || "Unknown Error",
|
|
351
|
+
name: layoutErr.name || "Error",
|
|
352
|
+
stack: isDevelopment ? layoutErr.stack : undefined,
|
|
353
|
+
};
|
|
354
|
+
jsx = await getErrorJSX(
|
|
355
|
+
reqPath,
|
|
356
|
+
query,
|
|
357
|
+
serializedError,
|
|
358
|
+
isDevelopment,
|
|
359
|
+
{ segment: "page" }
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
} else {
|
|
363
|
+
const prevLayoutIdCount = layoutSegmentStore.idCount;
|
|
364
|
+
const prevLayoutHoleCount = layoutSegmentStore.holeCount;
|
|
365
|
+
try {
|
|
366
|
+
const placeholder = createLayoutChildrenPlaceholder();
|
|
367
|
+
const testElement = React.createElement(Layout, props, placeholder);
|
|
368
|
+
const resolvedLayout = await runInLayoutSegment(
|
|
369
|
+
() => asyncRenderJSXToClientJSX(testElement),
|
|
370
|
+
layoutSegmentStore
|
|
371
|
+
);
|
|
372
|
+
jsx = replaceLayoutChildrenPlaceholder(resolvedLayout, jsx, placeholder);
|
|
307
373
|
} catch (layoutErr) {
|
|
374
|
+
layoutSegmentStore.idCount = prevLayoutIdCount;
|
|
375
|
+
layoutSegmentStore.holeCount = prevLayoutHoleCount;
|
|
308
376
|
console.warn(
|
|
309
377
|
`[Dinou] Layout ${layoutPath} failed during render, isolating layout error:`,
|
|
310
378
|
layoutErr?.message || layoutErr
|
package/dinou/core/handler.js
CHANGED
|
@@ -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)) {
|
|
@@ -1818,7 +1819,6 @@ async function handleRequest(request, platformContext = {}) {
|
|
|
1818
1819
|
return rendered;
|
|
1819
1820
|
});
|
|
1820
1821
|
} else if (!isDevelopment && (isPageReq || isLayoutReq) && isRoutePpr && isEdgeRuntime(platformContext)) {
|
|
1821
|
-
context._isPprRuntimeResume = true;
|
|
1822
1822
|
const storage = getStorageAdapter();
|
|
1823
1823
|
const cleanRel = cleanPath.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
1824
1824
|
if (isPageReq) {
|
|
@@ -1863,6 +1863,7 @@ async function handleRequest(request, platformContext = {}) {
|
|
|
1863
1863
|
request.url
|
|
1864
1864
|
);
|
|
1865
1865
|
if (shellJson) {
|
|
1866
|
+
context._isPprRuntimeResume = true;
|
|
1866
1867
|
try {
|
|
1867
1868
|
let cachedShellTree = deserializeJSX(shellJson);
|
|
1868
1869
|
const runSeg = isLayoutReq ? runInLayoutSegment : runInPageSegment;
|
|
@@ -1887,6 +1888,7 @@ async function handleRequest(request, platformContext = {}) {
|
|
|
1887
1888
|
}
|
|
1888
1889
|
}
|
|
1889
1890
|
if (!jsx) {
|
|
1891
|
+
context._isPprRuntimeResume = false;
|
|
1890
1892
|
jsx = await getJSX(reqPath, queryObj, isNotFound, isDevelopment, isPathBlocked, {
|
|
1891
1893
|
segment,
|
|
1892
1894
|
});
|
|
@@ -1910,7 +1912,9 @@ async function handleRequest(request, platformContext = {}) {
|
|
|
1910
1912
|
} catch (err) {
|
|
1911
1913
|
console.error(`[Dinou] Error rendering RSC ${segment}:`, err);
|
|
1912
1914
|
const serializedError = {
|
|
1913
|
-
message:
|
|
1915
|
+
message: isDevelopment
|
|
1916
|
+
? (err.message || "An error occurred in the Server Components render")
|
|
1917
|
+
: "An error occurred in the Server Components render",
|
|
1914
1918
|
name: err.name || "Error",
|
|
1915
1919
|
stack: isDevelopment ? err.stack : undefined,
|
|
1916
1920
|
};
|
package/dinou/core/navigation.js
CHANGED
|
@@ -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");
|