dinou 9.1.0 → 9.2.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,19 @@ 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.2.0] - 2026-11-06
9
+
10
+ ### Added
11
+ - **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):
12
+ - **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>_`).
13
+ - **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.
14
+ - **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.
15
+ - **`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.
16
+ - **`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.
17
+
18
+ ### Changed
19
+ - **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`.
20
+
8
21
  ## [9.1.0] - 2026-11-05
9
22
 
10
23
  ### 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.1.0-orange?style=flat-square)](https://www.npmjs.com/package/dinou)
4
+ [![Version](https://img.shields.io/badge/version-9.2.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.1.0")
17
+ .version("9.2.0")
18
18
  .option("-u, --unvendorized", "Run with standard node_modules dependencies instead of pre-bundled vendor packages");
19
19
 
20
20
  const isUnvendorizedRequested = () =>
@@ -304,10 +304,10 @@ function recordSlotTagsOnContext(
304
304
  for (const t of tags) {
305
305
  if (!t) continue;
306
306
  reqContext._slotTags.add(t);
307
- if (inLayout) {
308
- reqContext._layoutSlotTags.add(t);
309
- } else if (inPage) {
307
+ if (inPage) {
310
308
  reqContext._pageSlotTags.add(t);
309
+ } else if (inLayout) {
310
+ reqContext._layoutSlotTags.add(t);
311
311
  } else if (!reqContext._layoutSlotTags.has(t)) {
312
312
  reqContext._pageSlotTags.add(t);
313
313
  }
@@ -544,7 +544,8 @@ async function DinouCacheSlot(props) {
544
544
 
545
545
  const storageKey = `slots/${slotId}/slot.json`;
546
546
  const storage = getStorageAdapter();
547
- const runSlotScope = isNoCache ? (fn) => fn() : runInCachedSlot;
547
+ const runSlotScope = (fn) =>
548
+ runInCachedSlot(fn, { cached: !isNoCache, slotId });
548
549
 
549
550
  function wrapWithBoundary(content, alreadyRendered = false) {
550
551
  const Boundary = getCacheSlotBoundary();
@@ -583,8 +584,10 @@ async function DinouCacheSlot(props) {
583
584
  discoveringSlots.add(slotId);
584
585
  try {
585
586
  await runInSlotDiscovery(async () => {
586
- const childElement = typeof children === "function" ? await children() : children;
587
- await asyncRenderJSXToClientJSX(childElement);
587
+ await runSlotScope(async () => {
588
+ const childElement = typeof children === "function" ? await children() : children;
589
+ await asyncRenderJSXToClientJSX(childElement);
590
+ });
588
591
  });
589
592
  } catch (e) {
590
593
  } finally {
@@ -596,11 +599,15 @@ async function DinouCacheSlot(props) {
596
599
  });
597
600
 
598
601
  // When running inside a nested slot discovery pass, recursively discover any child slots
599
- if (isSlotDiscoveryActive() && !discoveringSlots.has(slotId)) {
600
- const ownEntry = slotRegistry.get(slotId);
601
- if (ownEntry && typeof ownEntry.discover === "function") {
602
- await ownEntry.discover();
602
+ // and short-circuit so discovery passes never overwrite storage cache with discovery renders.
603
+ if (isSlotDiscoveryActive()) {
604
+ if (!discoveringSlots.has(slotId)) {
605
+ const ownEntry = slotRegistry.get(slotId);
606
+ if (ownEntry && typeof ownEntry.discover === "function") {
607
+ await ownEntry.discover();
608
+ }
603
609
  }
610
+ return null;
604
611
  }
605
612
 
606
613
  if (isNoCache && !isSlotDiscoveryActive()) {
@@ -659,8 +666,10 @@ async function DinouCacheSlot(props) {
659
666
  } catch (e) {}
660
667
  }
661
668
  }
662
- const childElement = typeof children === "function" ? await children() : children;
663
- const directContent = await asyncRenderJSXToClientJSX(childElement);
669
+ const directContent = await runSlotScope(async () => {
670
+ const childElement = typeof children === "function" ? await children() : children;
671
+ return await asyncRenderJSXToClientJSX(childElement);
672
+ });
664
673
  commitSlotTags(slotTagsToCommit);
665
674
  return wrapWithBoundary(directContent, true);
666
675
  }
@@ -731,10 +740,13 @@ async function DinouCacheSlot(props) {
731
740
  !getContext()?._isPprRuntimeResume;
732
741
 
733
742
  const renderPromise = (async () => {
734
- const resolved = await runInCachedSlot(async () => {
735
- const childElement = typeof children === "function" ? await children() : children;
736
- return await asyncRenderJSXToClientJSX(childElement);
737
- });
743
+ const resolved = await runInCachedSlot(
744
+ async () => {
745
+ const childElement = typeof children === "function" ? await children() : children;
746
+ return await asyncRenderJSXToClientJSX(childElement);
747
+ },
748
+ { cached: true, slotId }
749
+ );
738
750
  const serialized = serializeJSX(resolved);
739
751
 
740
752
  const slotMeta = {
@@ -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 { asyncRenderJSXToClientJSX } from "./render-jsx-to-client-jsx.js";
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 { markPageRootElement, runInLayoutSegment } from "./ppr-context.js";
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(() => asyncRenderJSXToClientJSX(elementToRender));
250
- updatedSlotElement = elementToRender;
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
@@ -1818,7 +1818,6 @@ async function handleRequest(request, platformContext = {}) {
1818
1818
  return rendered;
1819
1819
  });
1820
1820
  } else if (!isDevelopment && (isPageReq || isLayoutReq) && isRoutePpr && isEdgeRuntime(platformContext)) {
1821
- context._isPprRuntimeResume = true;
1822
1821
  const storage = getStorageAdapter();
1823
1822
  const cleanRel = cleanPath.replace(/^\/+/, "").replace(/\/+$/, "");
1824
1823
  if (isPageReq) {
@@ -1863,6 +1862,7 @@ async function handleRequest(request, platformContext = {}) {
1863
1862
  request.url
1864
1863
  );
1865
1864
  if (shellJson) {
1865
+ context._isPprRuntimeResume = true;
1866
1866
  try {
1867
1867
  let cachedShellTree = deserializeJSX(shellJson);
1868
1868
  const runSeg = isLayoutReq ? runInLayoutSegment : runInPageSegment;
@@ -1887,6 +1887,7 @@ async function handleRequest(request, platformContext = {}) {
1887
1887
  }
1888
1888
  }
1889
1889
  if (!jsx) {
1890
+ context._isPprRuntimeResume = false;
1890
1891
  jsx = await getJSX(reqPath, queryObj, isNotFound, isDevelopment, isPathBlocked, {
1891
1892
  segment,
1892
1893
  });
@@ -1910,7 +1911,9 @@ async function handleRequest(request, platformContext = {}) {
1910
1911
  } catch (err) {
1911
1912
  console.error(`[Dinou] Error rendering RSC ${segment}:`, err);
1912
1913
  const serializedError = {
1913
- message: err.message || "Unknown Error",
1914
+ message: isDevelopment
1915
+ ? (err.message || "An error occurred in the Server Components render")
1916
+ : "An error occurred in the Server Components render",
1914
1917
  name: err.name || "Error",
1915
1918
  stack: isDevelopment ? err.stack : undefined,
1916
1919
  };
@@ -10,6 +10,8 @@ const cachedSlotStorage = new AsyncLocalStorage();
10
10
  const slotDiscoveryStorage = new AsyncLocalStorage();
11
11
  const runtimeStaticSuspenseStorage = new AsyncLocalStorage();
12
12
  const pageRootElements = new WeakSet();
13
+ const layoutRootElements = new WeakSet();
14
+ const layoutChildrenPlaceholders = new WeakSet();
13
15
 
14
16
  const NO_DYNAMIC_HOOK_KEY = Symbol.for("dinou.ppr.noDynamic.hook");
15
17
  export const SKIP_STATIC_SUSPENSE_SYMBOL = Symbol.for("dinou.ppr.skipStatic");
@@ -23,8 +25,23 @@ export function runInRuntimeStaticSuspense(callback) {
23
25
  );
24
26
  }
25
27
 
26
- export function runInRuntimeDynamicHole(callback) {
27
- return runtimeStaticSuspenseStorage.run({ active: false, depth: 0 }, callback);
28
+ export function runInRuntimeDynamicHole(callback, holeId = null) {
29
+ const prev = runtimeStaticSuspenseStorage.getStore();
30
+ return runtimeStaticSuspenseStorage.run(
31
+ {
32
+ active: false,
33
+ depth: 0,
34
+ holeId: holeId || prev?.holeId || null,
35
+ idCount: 0,
36
+ childHoleCount: 0,
37
+ },
38
+ callback
39
+ );
40
+ }
41
+
42
+ export function getActiveRuntimeDynamicHoleStore() {
43
+ const store = runtimeStaticSuspenseStorage.getStore();
44
+ return store && store.holeId ? store : null;
28
45
  }
29
46
 
30
47
  export function isRuntimeStaticSuspenseActive() {
@@ -67,9 +84,25 @@ export function isNoDynamicActive() {
67
84
  return Boolean(store && store.noDynamic);
68
85
  }
69
86
 
70
- export function runInCachedSlot(callback) {
87
+ export function runInCachedSlot(callback, options = {}) {
71
88
  const prev = cachedSlotStorage.getStore();
72
- return cachedSlotStorage.run({ depth: (prev?.depth || 0) + 1 }, callback);
89
+ const isCached = options?.cached !== false;
90
+ const slotId =
91
+ typeof options === "string"
92
+ ? options
93
+ : options?.slotId || prev?.slotId || null;
94
+ return cachedSlotStorage.run(
95
+ {
96
+ depth: (prev?.depth || 0) + (isCached ? 1 : 0),
97
+ slotId,
98
+ idCount: 0,
99
+ },
100
+ callback
101
+ );
102
+ }
103
+
104
+ export function getActiveCachedSlotStore() {
105
+ return cachedSlotStorage.getStore() || null;
73
106
  }
74
107
 
75
108
  export function isInsideCachedSlot() {
@@ -95,20 +128,68 @@ export function isPageRootElement(el) {
95
128
  return Boolean(el && typeof el === "object" && pageRootElements.has(el));
96
129
  }
97
130
 
98
- export function runInPageSegment(callback) {
99
- return pageSegmentStorage.run({ active: true }, callback);
131
+ export function markLayoutRootElement(el) {
132
+ if (el && typeof el === "object") {
133
+ layoutRootElements.add(el);
134
+ }
135
+ return el;
136
+ }
137
+
138
+ export function isLayoutRootElement(el) {
139
+ return Boolean(el && typeof el === "object" && layoutRootElements.has(el));
140
+ }
141
+
142
+ export function createLayoutChildrenPlaceholder() {
143
+ const placeholder = {
144
+ $$typeof: Symbol.for("react.transitional.element"),
145
+ type: Symbol.for("dinou.layout.children.placeholder"),
146
+ key: null,
147
+ ref: null,
148
+ props: {},
149
+ };
150
+ layoutChildrenPlaceholders.add(placeholder);
151
+ return placeholder;
152
+ }
153
+
154
+ export function isLayoutChildrenPlaceholder(el) {
155
+ return Boolean(
156
+ el &&
157
+ typeof el === "object" &&
158
+ (layoutChildrenPlaceholders.has(el) ||
159
+ el.type === Symbol.for("dinou.layout.children.placeholder"))
160
+ );
161
+ }
162
+
163
+ export function runInPageSegment(callback, storeOverride = null) {
164
+ const prev = pageSegmentStorage.getStore();
165
+ const store =
166
+ storeOverride || prev || { active: true, idCount: 0, holeCount: 0 };
167
+ return pageSegmentStorage.run(store, callback);
168
+ }
169
+
170
+ export function getActivePageSegmentStore() {
171
+ return pageSegmentStorage.getStore() || null;
100
172
  }
101
173
 
102
174
  export function isInsidePageSegment() {
103
175
  return Boolean(pageSegmentStorage.getStore()?.active);
104
176
  }
105
177
 
106
- export function runInLayoutSegment(callback) {
107
- return layoutSegmentStorage.run({ active: true }, callback);
178
+ export function runInLayoutSegment(callback, storeOverride = null) {
179
+ const prev = layoutSegmentStorage.getStore();
180
+ const store =
181
+ storeOverride || prev || { active: true, idCount: 0, holeCount: 0 };
182
+ return layoutSegmentStorage.run(store, callback);
183
+ }
184
+
185
+ export function getActiveLayoutSegmentStore() {
186
+ return layoutSegmentStorage.getStore() || null;
108
187
  }
109
188
 
110
189
  export function isInsideLayoutSegment() {
111
- return Boolean(layoutSegmentStorage.getStore()?.active);
190
+ return Boolean(
191
+ layoutSegmentStorage.getStore()?.active && !isInsidePageSegment()
192
+ );
112
193
  }
113
194
 
114
195
  /**
@@ -209,7 +290,29 @@ export function getPprHoleCounter() {
209
290
  export function runInSuspense(callback, explicitHoleId = null) {
210
291
  const store = getPprStore();
211
292
  if (!store) {
212
- return callback(null, null);
293
+ let holeId = explicitHoleId;
294
+ if (!holeId) {
295
+ const holeStore = getActiveRuntimeDynamicHoleStore();
296
+ const layoutStore = getActiveLayoutSegmentStore();
297
+ const pageStore = getActivePageSegmentStore();
298
+ if (holeStore && holeStore.holeId) {
299
+ holeStore.childHoleCount = (holeStore.childHoleCount || 0) + 1;
300
+ holeId = `${holeStore.holeId}-${holeStore.childHoleCount}`;
301
+ } else if (
302
+ layoutStore &&
303
+ layoutStore.active &&
304
+ !isInsidePageSegment()
305
+ ) {
306
+ layoutStore.holeCount = (layoutStore.holeCount || 0) + 1;
307
+ holeId = `layout-hole-${layoutStore.holeCount}`;
308
+ } else if (pageStore && pageStore.active) {
309
+ pageStore.holeCount = (pageStore.holeCount || 0) + 1;
310
+ holeId = `ppr-hole-${pageStore.holeCount}`;
311
+ } else {
312
+ holeId = "ppr-hole-1";
313
+ }
314
+ }
315
+ return callback(holeId, null);
213
316
  }
214
317
  let holeId = explicitHoleId;
215
318
  if (!holeId) {
@@ -359,6 +462,7 @@ export default {
359
462
  SKIP_STATIC_SUSPENSE_SYMBOL,
360
463
  runInRuntimeStaticSuspense,
361
464
  runInRuntimeDynamicHole,
465
+ getActiveRuntimeDynamicHoleStore,
362
466
  isRuntimeStaticSuspenseActive,
363
467
  resetComponentNoDynamicFlag,
364
468
  consumeComponentNoDynamicFlag,
@@ -367,8 +471,16 @@ export default {
367
471
  isInsideCachedSlot,
368
472
  runInSlotDiscovery,
369
473
  isSlotDiscoveryActive,
474
+ markPageRootElement,
475
+ isPageRootElement,
476
+ markLayoutRootElement,
477
+ isLayoutRootElement,
478
+ createLayoutChildrenPlaceholder,
479
+ isLayoutChildrenPlaceholder,
370
480
  runInPageSegment,
371
481
  isInsidePageSegment,
482
+ runInLayoutSegment,
483
+ isInsideLayoutSegment,
372
484
  runWithPprContext,
373
485
  getPprStore,
374
486
  isPprBuildActive,
@@ -9,12 +9,23 @@ import { renderRSCStream } from "./rsc-renderer.js";
9
9
  import { getClientManifest } from "./manifest-provider.js";
10
10
  import { requestStorage, setCurrentContext } from "./request-context.js";
11
11
  import getJSX from "./get-jsx.js";
12
+ import {
13
+ asyncRenderJSXToClientJSX,
14
+ invokeWithServerHooksDispatcher,
15
+ } from "./render-jsx-to-client-jsx.js";
12
16
  import {
13
17
  SKIP_STATIC_SUSPENSE_SYMBOL,
14
18
  runInRuntimeStaticSuspense,
15
19
  runInRuntimeDynamicHole,
16
20
  } from "./ppr-context.js";
17
21
 
22
+ async function PprDynamicHoleBoundary({ holeId, children }) {
23
+ return await runInRuntimeDynamicHole(
24
+ () => asyncRenderJSXToClientJSX(children),
25
+ holeId
26
+ );
27
+ }
28
+
18
29
  function escapeHtml(str) {
19
30
  return String(str)
20
31
  .replace(/&/g, "&amp;")
@@ -114,7 +125,9 @@ async function spliceDynamicHolesIntoShell(
114
125
  }
115
126
  if (typeof current?.type === "function") {
116
127
  try {
117
- const evaluated = await current.type(current.props || {});
128
+ const evaluated = await invokeWithServerHooksDispatcher(() =>
129
+ current.type(current.props || {})
130
+ );
118
131
  await traverse(evaluated);
119
132
  } catch (err) {
120
133
  if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
@@ -134,7 +147,9 @@ async function spliceDynamicHolesIntoShell(
134
147
  return;
135
148
  }
136
149
  try {
137
- const rendered = await current.type.render(current.props || {}, current.ref);
150
+ const rendered = await invokeWithServerHooksDispatcher(() =>
151
+ current.type.render(current.props || {}, current.ref)
152
+ );
138
153
  await traverse(rendered);
139
154
  } catch (err) {
140
155
  if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
@@ -155,8 +170,21 @@ async function spliceDynamicHolesIntoShell(
155
170
  }
156
171
  try {
157
172
  const innerComp = current.type.type;
158
- const rendered =
159
- typeof innerComp === "function" ? await innerComp(current.props || {}) : null;
173
+ let rendered = null;
174
+ if (typeof innerComp === "function") {
175
+ rendered = await invokeWithServerHooksDispatcher(() =>
176
+ innerComp(current.props || {})
177
+ );
178
+ } else if (
179
+ typeof innerComp === "object" &&
180
+ innerComp !== null &&
181
+ innerComp.$$typeof === Symbol.for("react.forward_ref") &&
182
+ typeof innerComp.render === "function"
183
+ ) {
184
+ rendered = await invokeWithServerHooksDispatcher(() =>
185
+ innerComp.render(current.props || {}, current.ref)
186
+ );
187
+ }
160
188
  await traverse(rendered);
161
189
  } catch (err) {
162
190
  if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
@@ -173,7 +201,18 @@ async function spliceDynamicHolesIntoShell(
173
201
  holeIndex++;
174
202
  const currentHoleId = `ppr-hole-${holeIndex}`;
175
203
  if (knownHoleIds.has(currentHoleId)) {
176
- liveHolesMap.set(currentHoleId, current);
204
+ const wrappedHole = React.createElement(
205
+ React.Suspense,
206
+ {
207
+ ...(current.props || {}),
208
+ ...(current.key != null ? { key: current.key } : {}),
209
+ children: React.createElement(PprDynamicHoleBoundary, {
210
+ holeId: currentHoleId,
211
+ children: current.props?.children,
212
+ }),
213
+ }
214
+ );
215
+ liveHolesMap.set(currentHoleId, wrappedHole);
177
216
  return;
178
217
  }
179
218
  const runStaticScope = staticParentHoleIds.has(currentHoleId)
@@ -320,7 +359,9 @@ async function streamDynamicHoles(
320
359
  // Handle React Server Component function
321
360
  if (typeof current?.type === "function") {
322
361
  try {
323
- const evaluated = await current.type(current.props || {});
362
+ const evaluated = await invokeWithServerHooksDispatcher(() =>
363
+ current.type(current.props || {})
364
+ );
324
365
  await traverse(evaluated);
325
366
  } catch (err) {
326
367
  if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
@@ -342,7 +383,9 @@ async function streamDynamicHoles(
342
383
  return;
343
384
  }
344
385
  try {
345
- const rendered = await current.type.render(current.props || {}, current.ref);
386
+ const rendered = await invokeWithServerHooksDispatcher(() =>
387
+ current.type.render(current.props || {}, current.ref)
388
+ );
346
389
  await traverse(rendered);
347
390
  } catch (err) {
348
391
  if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
@@ -365,8 +408,21 @@ async function streamDynamicHoles(
365
408
  }
366
409
  try {
367
410
  const innerComp = current.type.type;
368
- const rendered =
369
- typeof innerComp === "function" ? await innerComp(current.props || {}) : null;
411
+ let rendered = null;
412
+ if (typeof innerComp === "function") {
413
+ rendered = await invokeWithServerHooksDispatcher(() =>
414
+ innerComp(current.props || {})
415
+ );
416
+ } else if (
417
+ typeof innerComp === "object" &&
418
+ innerComp !== null &&
419
+ innerComp.$$typeof === Symbol.for("react.forward_ref") &&
420
+ typeof innerComp.render === "function"
421
+ ) {
422
+ rendered = await invokeWithServerHooksDispatcher(() =>
423
+ innerComp.render(current.props || {}, current.ref)
424
+ );
425
+ }
370
426
  await traverse(rendered);
371
427
  } catch (err) {
372
428
  if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
@@ -397,7 +453,8 @@ async function streamDynamicHoles(
397
453
  try {
398
454
  let html = "";
399
455
  if (platformContext && platformContext.renderHtmlStream) {
400
- const rscStream = renderRSCStream(children, clientManifest, { runtime: "edge" });
456
+ const resolvedChildren = await asyncRenderJSXToClientJSX(children);
457
+ const rscStream = renderRSCStream(resolvedChildren, clientManifest, { runtime: "edge" });
401
458
  const htmlStream = await platformContext.renderHtmlStream(rscStream, {
402
459
  bootstrapModules: [],
403
460
  });
@@ -415,7 +472,7 @@ async function streamDynamicHoles(
415
472
  const errChunk = `\n<template id="ppr-content-${currentHoleId}"><div style="color:#e11d48;padding:8px 12px;background:#fff1f2;border:1px solid #fecdd3;border-radius:6px;font-size:0.875rem;font-family:system-ui,sans-serif;">[PPR Error: ${errMsg}]</div></template>\n<script>(function(){var c=document.getElementById("ppr-content-${currentHoleId}");if(!c)return;var b=document.getElementById("B:${currentBoundaryIndex}");var t=document.querySelector('[data-ppr-hole="${currentHoleId}"]')||(b?b.nextElementSibling:null);try{if(t){if(c.content){t.replaceWith(c.content);}else{t.replaceWith.apply(t,Array.from(c.childNodes));}}}finally{c.remove();}})();</script>\n`;
416
473
  await writer.write(encoder.encode(errChunk));
417
474
  }
418
- })());
475
+ })(), currentHoleId);
419
476
  holePromises.push(promise);
420
477
  return;
421
478
  }