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.
@@ -1,17 +1,27 @@
1
1
  import React from "react";
2
+ import { createRequire } from "node:module";
2
3
  import {
3
4
  isPprBuildActive,
5
+ getPprStore,
4
6
  isInsideSuspense,
5
7
  isInsideOuterSuspenseOutsideSlot,
6
8
  rollbackPprHolesAfter,
7
9
  isInsideCachedSlot,
10
+ getActiveCachedSlotStore,
11
+ getActiveRuntimeDynamicHoleStore,
12
+ runInRuntimeDynamicHole,
8
13
  runInSuspense,
9
14
  getPprHoleCounter,
10
15
  commitPprSuspenseEffects,
11
16
  registerHole,
12
17
  markDynamicAccess,
13
18
  isPageRootElement,
19
+ isLayoutRootElement,
20
+ isLayoutChildrenPlaceholder,
14
21
  runInPageSegment,
22
+ runInLayoutSegment,
23
+ getActivePageSegmentStore,
24
+ getActiveLayoutSegmentStore,
15
25
  resetComponentNoDynamicFlag,
16
26
  consumeComponentNoDynamicFlag,
17
27
  isNoDynamicActive,
@@ -19,6 +29,327 @@ import {
19
29
  } from "./ppr-context.js";
20
30
  import { getContext } from "./request-context.js";
21
31
 
32
+ const REACT_MEMO_CACHE_SENTINEL = Symbol.for("react.memo_cache_sentinel");
33
+ const REACT_CONTEXT_TYPE = Symbol.for("react.context");
34
+ const CLIENT_REFERENCE_TAG = Symbol.for("react.client.reference");
35
+
36
+ let fallbackRenderSeq = 0;
37
+
38
+ function unsupportedHook() {
39
+ throw new Error("This Hook is not supported in Server Components.");
40
+ }
41
+
42
+ function unsupportedRefresh() {
43
+ throw new Error("Refreshing the cache is not supported in Server Components.");
44
+ }
45
+
46
+ function unsupportedContext() {
47
+ throw new Error("Cannot read a Client Context from a Server Component.");
48
+ }
49
+
50
+ function sanitizeIdSegment(val) {
51
+ return String(val || "slot").replace(/[^a-zA-Z0-9_-]/g, "_");
52
+ }
53
+
54
+ function useServerId() {
55
+ const slotStore = getActiveCachedSlotStore();
56
+ if (slotStore && slotStore.slotId) {
57
+ slotStore.idCount = (slotStore.idCount || 0) + 1;
58
+ const safeSlot = sanitizeIdSegment(slotStore.slotId);
59
+ return `_slot_${safeSlot}_dS_${slotStore.idCount.toString(32)}_`;
60
+ }
61
+ if (isSlotDiscoveryActive()) {
62
+ return "_discovery_dS_";
63
+ }
64
+ const holeStore = getActiveRuntimeDynamicHoleStore();
65
+ if (holeStore && holeStore.holeId) {
66
+ holeStore.idCount = (holeStore.idCount || 0) + 1;
67
+ const safeHole = sanitizeIdSegment(holeStore.holeId);
68
+ return `_hole_${safeHole}_dS_${holeStore.idCount.toString(32)}_`;
69
+ }
70
+ const pageStore = getActivePageSegmentStore();
71
+ if (pageStore && pageStore.active) {
72
+ pageStore.idCount = (pageStore.idCount || 0) + 1;
73
+ return `_page_dS_${pageStore.idCount.toString(32)}_`;
74
+ }
75
+ const layoutStore = getActiveLayoutSegmentStore();
76
+ if (layoutStore && layoutStore.active) {
77
+ layoutStore.idCount = (layoutStore.idCount || 0) + 1;
78
+ return `_layout_dS_${layoutStore.idCount.toString(32)}_`;
79
+ }
80
+ const reqCtx = getContext();
81
+ if (reqCtx) {
82
+ reqCtx._dinouUseIdCount = (reqCtx._dinouUseIdCount || 0) + 1;
83
+ return `_page_dS_${reqCtx._dinouUseIdCount.toString(32)}_`;
84
+ }
85
+ const id = ++fallbackRenderSeq;
86
+ return `_dS_${id.toString(32)}_`;
87
+ }
88
+
89
+ function snapshotActiveIdCounts() {
90
+ const slotStore = getActiveCachedSlotStore();
91
+ const holeStore = getActiveRuntimeDynamicHoleStore();
92
+ const pageStore = getActivePageSegmentStore();
93
+ const layoutStore = getActiveLayoutSegmentStore();
94
+ const reqCtx = getContext();
95
+ return {
96
+ slotStore,
97
+ slotCount: slotStore ? slotStore.idCount || 0 : 0,
98
+ holeStore,
99
+ holeCount: holeStore ? holeStore.idCount || 0 : 0,
100
+ pageStore,
101
+ pageCount: pageStore ? pageStore.idCount || 0 : 0,
102
+ layoutStore,
103
+ layoutCount: layoutStore ? layoutStore.idCount || 0 : 0,
104
+ reqCtx,
105
+ reqCount: reqCtx ? reqCtx._dinouUseIdCount || 0 : 0,
106
+ fallbackSeq: fallbackRenderSeq,
107
+ };
108
+ }
109
+
110
+ function restoreActiveIdCounts(snap) {
111
+ if (!snap) return;
112
+ if (snap.slotStore) snap.slotStore.idCount = snap.slotCount;
113
+ if (snap.holeStore) snap.holeStore.idCount = snap.holeCount;
114
+ if (snap.pageStore) snap.pageStore.idCount = snap.pageCount;
115
+ if (snap.layoutStore) snap.layoutStore.idCount = snap.layoutCount;
116
+ if (snap.reqCtx) snap.reqCtx._dinouUseIdCount = snap.reqCount;
117
+ fallbackRenderSeq = snap.fallbackSeq;
118
+ }
119
+
120
+ function useServerUsable(usable) {
121
+ if (
122
+ (usable !== null && typeof usable === "object") ||
123
+ typeof usable === "function"
124
+ ) {
125
+ if (typeof usable.then === "function") {
126
+ if (usable.status === "fulfilled") {
127
+ return usable.value;
128
+ }
129
+ if (usable.status === "rejected") {
130
+ throw usable.reason;
131
+ }
132
+ if (typeof usable.status !== "string") {
133
+ usable.status = "pending";
134
+ usable.then(
135
+ (fulfilledValue) => {
136
+ if (usable.status === "pending") {
137
+ usable.status = "fulfilled";
138
+ usable.value = fulfilledValue;
139
+ }
140
+ },
141
+ (error) => {
142
+ if (usable.status === "pending") {
143
+ usable.status = "rejected";
144
+ usable.reason = error;
145
+ }
146
+ }
147
+ );
148
+ if (usable.status === "fulfilled") {
149
+ return usable.value;
150
+ }
151
+ if (usable.status === "rejected") {
152
+ throw usable.reason;
153
+ }
154
+ }
155
+ throw usable;
156
+ }
157
+ if (usable.$$typeof === REACT_CONTEXT_TYPE) {
158
+ unsupportedContext();
159
+ }
160
+ if (usable.$$typeof === CLIENT_REFERENCE_TAG) {
161
+ if (usable.value != null && usable.value.$$typeof === REACT_CONTEXT_TYPE) {
162
+ unsupportedContext();
163
+ }
164
+ throw new Error("Cannot use() an already resolved Client Reference.");
165
+ }
166
+ }
167
+ throw new Error("An unsupported type was passed to use(): " + String(usable));
168
+ }
169
+
170
+ const DinouServerHooksDispatcher = {
171
+ readContext: unsupportedContext,
172
+ use: useServerUsable,
173
+ useCallback(callback) {
174
+ return callback;
175
+ },
176
+ useContext: unsupportedContext,
177
+ useEffect: unsupportedHook,
178
+ useImperativeHandle: unsupportedHook,
179
+ useLayoutEffect: unsupportedHook,
180
+ useInsertionEffect: unsupportedHook,
181
+ useMemo(nextCreate) {
182
+ return nextCreate();
183
+ },
184
+ useReducer: unsupportedHook,
185
+ useRef: unsupportedHook,
186
+ useState: unsupportedHook,
187
+ useDebugValue() {},
188
+ useDeferredValue: unsupportedHook,
189
+ useTransition: unsupportedHook,
190
+ useSyncExternalStore: unsupportedHook,
191
+ useId: useServerId,
192
+ useHostTransitionStatus: unsupportedHook,
193
+ useFormState: unsupportedHook,
194
+ useActionState: unsupportedHook,
195
+ useOptimistic: unsupportedHook,
196
+ useMemoCache(size) {
197
+ const data = new Array(size);
198
+ for (let i = 0; i < size; i++) {
199
+ data[i] = REACT_MEMO_CACHE_SENTINEL;
200
+ }
201
+ return data;
202
+ },
203
+ useCacheRefresh() {
204
+ return unsupportedRefresh;
205
+ },
206
+ useEffectEvent: unsupportedHook,
207
+ };
208
+
209
+ function getCallerComponentSite() {
210
+ const stack = new Error().stack;
211
+ if (!stack) return null;
212
+ const lines = stack.split("\n");
213
+ for (let i = 2; i < lines.length; i++) {
214
+ const line = lines[i];
215
+ if (
216
+ !line.includes("useServerId") &&
217
+ !line.includes("patchDispatcherObject") &&
218
+ !line.includes("exports.useId") &&
219
+ !line.includes("exports.use ") &&
220
+ !line.includes("Object.useId") &&
221
+ !line.includes("Object.use ")
222
+ ) {
223
+ return line.trim();
224
+ }
225
+ }
226
+ return null;
227
+ }
228
+
229
+ function patchDispatcherObject(dispatcher, internals) {
230
+ if (!dispatcher || typeof dispatcher !== "object" || dispatcher === DinouServerHooksDispatcher) {
231
+ return;
232
+ }
233
+ if (dispatcher._dinouWrappedDispatcher) {
234
+ return;
235
+ }
236
+ const origUse = typeof dispatcher.use === "function" ? dispatcher.use : null;
237
+ let activeOwnerKey = null;
238
+ let activeIdSnap = null;
239
+
240
+ try {
241
+ dispatcher.useId = function dinouPatchedUseId() {
242
+ const owner = internals?.A?.getOwner?.() || getCallerComponentSite();
243
+ if (owner !== activeOwnerKey || !activeIdSnap) {
244
+ activeOwnerKey = owner;
245
+ activeIdSnap = snapshotActiveIdCounts();
246
+ }
247
+ return useServerId();
248
+ };
249
+ if (origUse && origUse !== useServerUsable) {
250
+ dispatcher.use = function dinouPatchedUse(usable) {
251
+ const owner = internals?.A?.getOwner?.() || getCallerComponentSite();
252
+ try {
253
+ return origUse.call(this, usable);
254
+ } catch (err) {
255
+ if (activeIdSnap && (!owner || !activeOwnerKey || owner === activeOwnerKey)) {
256
+ restoreActiveIdCounts(activeIdSnap);
257
+ }
258
+ activeIdSnap = null;
259
+ activeOwnerKey = null;
260
+ throw err;
261
+ }
262
+ };
263
+ }
264
+ Object.defineProperty(dispatcher, "_dinouWrappedDispatcher", {
265
+ value: true,
266
+ enumerable: false,
267
+ configurable: true,
268
+ });
269
+ } catch (_) {}
270
+ }
271
+
272
+ function patchInternalsDispatcherSetter(internals) {
273
+ if (!internals || typeof internals !== "object" || internals._dinouPatchedH) {
274
+ return;
275
+ }
276
+ let currentH = internals.H;
277
+ if (currentH && typeof currentH === "object") {
278
+ patchDispatcherObject(currentH, internals);
279
+ }
280
+ try {
281
+ Object.defineProperty(internals, "H", {
282
+ configurable: true,
283
+ enumerable: true,
284
+ get() {
285
+ return currentH;
286
+ },
287
+ set(nextH) {
288
+ if (nextH && typeof nextH === "object") {
289
+ patchDispatcherObject(nextH, internals);
290
+ }
291
+ currentH = nextH;
292
+ },
293
+ });
294
+ internals._dinouPatchedH = true;
295
+ } catch (_) {}
296
+ }
297
+
298
+ let _cachedReactInternalsList = null;
299
+ function getReactInternalsList() {
300
+ if (_cachedReactInternalsList) return _cachedReactInternalsList;
301
+ const set = new Set();
302
+ const addFromModule = (mod) => {
303
+ if (!mod || typeof mod !== "object") return;
304
+ const s = mod.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
305
+ const c = mod.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
306
+ if (s && typeof s === "object" && "H" in s) {
307
+ patchInternalsDispatcherSetter(s);
308
+ set.add(s);
309
+ }
310
+ if (c && typeof c === "object" && "H" in c) {
311
+ patchInternalsDispatcherSetter(c);
312
+ set.add(c);
313
+ }
314
+ };
315
+ addFromModule(React);
316
+ try {
317
+ const req = createRequire(import.meta.url);
318
+ try {
319
+ addFromModule(req("react/index.js"));
320
+ } catch (_) {}
321
+ try {
322
+ addFromModule(req("react/react.react-server.js"));
323
+ } catch (_) {}
324
+ } catch (_) {}
325
+ _cachedReactInternalsList = Array.from(set);
326
+ return _cachedReactInternalsList;
327
+ }
328
+
329
+ function ensureServerHooksPatched() {
330
+ const list = getReactInternalsList();
331
+ for (const internals of list) {
332
+ patchInternalsDispatcherSetter(internals);
333
+ }
334
+ }
335
+
336
+ ensureServerHooksPatched();
337
+
338
+ function invokeWithServerHooksDispatcher(callFn) {
339
+ const internalsList = getReactInternalsList();
340
+ const prevDispatchers = internalsList.map((internals) => internals.H);
341
+ for (const internals of internalsList) {
342
+ internals.H = DinouServerHooksDispatcher;
343
+ }
344
+ try {
345
+ return callFn();
346
+ } finally {
347
+ for (let i = 0; i < internalsList.length; i++) {
348
+ internalsList[i].H = prevDispatchers[i];
349
+ }
350
+ }
351
+ }
352
+
22
353
  function isThenable(val) {
23
354
  return (
24
355
  val !== null &&
@@ -32,25 +363,64 @@ function isCacheSlotComponent(fn) {
32
363
  return Boolean(fn.$$dinouCacheSlot || fn.name === "DinouCacheSlot");
33
364
  }
34
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
+
35
378
  async function invokeServerComponentInPpr(fn, callFn) {
36
- resetComponentNoDynamicFlag();
37
- const rawResult = callFn();
38
- const optedOut = consumeComponentNoDynamicFlag();
39
- if (
40
- isThenable(rawResult) &&
41
- !isCacheSlotComponent(fn) &&
42
- isPprBuildActive() &&
43
- isInsideOuterSuspenseOutsideSlot() &&
44
- !isSlotDiscoveryActive() &&
45
- !optedOut &&
46
- !isNoDynamicActive()
47
- ) {
379
+ while (true) {
380
+ resetComponentNoDynamicFlag();
381
+ const idSnap = snapshotActiveIdCounts();
382
+ let rawResult;
48
383
  try {
49
- rawResult.then(null, () => {});
50
- } catch (_) {}
51
- markDynamicAccess("async-suspense");
384
+ rawResult = invokeWithServerHooksDispatcher(callFn);
385
+ } catch (thrown) {
386
+ restoreActiveIdCounts(idSnap);
387
+ const optedOutOnThrow = consumeComponentNoDynamicFlag();
388
+ if (isThenable(thrown)) {
389
+ if (
390
+ !isCacheSlotComponent(fn) &&
391
+ isPprBuildActive() &&
392
+ isInsideOuterSuspenseOutsideSlot() &&
393
+ !isSlotDiscoveryActive() &&
394
+ !optedOutOnThrow &&
395
+ !isNoDynamicActive()
396
+ ) {
397
+ try {
398
+ thrown.then(null, () => {});
399
+ } catch (_) {}
400
+ markDynamicAccess("async-suspense");
401
+ }
402
+ await thrown;
403
+ continue;
404
+ }
405
+ throw thrown;
406
+ }
407
+ const optedOut = consumeComponentNoDynamicFlag();
408
+ if (
409
+ isThenable(rawResult) &&
410
+ !isCacheSlotComponent(fn) &&
411
+ isPprBuildActive() &&
412
+ isInsideOuterSuspenseOutsideSlot() &&
413
+ !isSlotDiscoveryActive() &&
414
+ !optedOut &&
415
+ !isNoDynamicActive()
416
+ ) {
417
+ try {
418
+ rawResult.then(null, () => {});
419
+ } catch (_) {}
420
+ markDynamicAccess("async-suspense");
421
+ }
422
+ return await rawResult;
52
423
  }
53
- return await rawResult;
54
424
  }
55
425
 
56
426
  function cloneWithDevProps(jsx, newProps, resolvedKey, overrideType) {
@@ -80,6 +450,54 @@ function cloneWithDevProps(jsx, newProps, resolvedKey, overrideType) {
80
450
  return cloned;
81
451
  }
82
452
 
453
+ function replaceLayoutChildrenPlaceholder(node, replacement, placeholder) {
454
+ if (node == null || typeof node !== "object") return node;
455
+ if (node === placeholder || isLayoutChildrenPlaceholder(node)) {
456
+ return replacement;
457
+ }
458
+ if (Array.isArray(node)) {
459
+ let changed = false;
460
+ const mapped = node.map((item) => {
461
+ const updated = replaceLayoutChildrenPlaceholder(item, replacement, placeholder);
462
+ if (updated !== item) changed = true;
463
+ return updated;
464
+ });
465
+ return changed ? mapped : node;
466
+ }
467
+ if (node.$$typeof === Symbol.for("react.transitional.element")) {
468
+ if (node.props && typeof node.props === "object") {
469
+ let changed = false;
470
+ const newProps = { ...node.props };
471
+ for (const [k, v] of Object.entries(node.props)) {
472
+ if (v && typeof v === "object") {
473
+ const updated = replaceLayoutChildrenPlaceholder(v, replacement, placeholder);
474
+ if (updated !== v) {
475
+ newProps[k] = updated;
476
+ changed = true;
477
+ }
478
+ }
479
+ }
480
+ if (changed) {
481
+ return cloneWithDevProps(node, newProps, node.key);
482
+ }
483
+ }
484
+ return node;
485
+ }
486
+ if (node instanceof Promise) return node;
487
+ let changed = false;
488
+ const clone = { ...node };
489
+ for (const [k, v] of Object.entries(node)) {
490
+ if (v && typeof v === "object") {
491
+ const updated = replaceLayoutChildrenPlaceholder(v, replacement, placeholder);
492
+ if (updated !== v) {
493
+ clone[k] = updated;
494
+ changed = true;
495
+ }
496
+ }
497
+ }
498
+ return changed ? clone : node;
499
+ }
500
+
83
501
  // Function to check if a component is a client component
84
502
  function isClientComponent(type) {
85
503
  if (!type) {
@@ -92,17 +510,29 @@ function isClientComponent(type) {
92
510
  );
93
511
  }
94
512
 
513
+ async function DinouSuspenseHoleBoundary({ holeId, children }) {
514
+ return await runInRuntimeDynamicHole(
515
+ () => asyncRenderJSXToClientJSX(children),
516
+ holeId
517
+ );
518
+ }
519
+
95
520
  async function asyncRenderJSXToClientJSX(jsx, key = null) {
96
521
  if (isPageRootElement(jsx)) {
97
522
  return await runInPageSegment(async () => {
98
523
  const resolved = await asyncRenderJSXToClientJSXInner(jsx, key);
99
524
  const ctx = getContext();
100
- if (ctx) {
525
+ if (ctx && getPprStore()) {
101
526
  ctx._resolvedPageClientJsx = resolved;
102
527
  }
103
528
  return resolved;
104
529
  });
105
530
  }
531
+ if (isLayoutRootElement(jsx)) {
532
+ return await runInLayoutSegment(async () => {
533
+ return await asyncRenderJSXToClientJSXInner(jsx, key);
534
+ });
535
+ }
106
536
  return await asyncRenderJSXToClientJSXInner(jsx, key);
107
537
  }
108
538
 
@@ -117,21 +547,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
117
547
  ) {
118
548
  return jsx;
119
549
  } else if (Array.isArray(jsx)) {
120
- if (isPprBuildActive()) {
121
- const results = [];
122
- for (const child of jsx) {
123
- results.push(await asyncRenderJSXToClientJSX(child, child?.key ?? null));
124
- }
125
- return results;
550
+ const results = [];
551
+ for (const child of jsx) {
552
+ results.push(await asyncRenderJSXToClientJSX(child, child?.key ?? null));
126
553
  }
127
- return await Promise.all(
128
- jsx.map((child) =>
129
- asyncRenderJSXToClientJSX(
130
- child,
131
- child?.key ?? null
132
- )
133
- )
134
- );
554
+ return results;
135
555
  } else if (typeof jsx === "symbol") {
136
556
  if (jsx === Symbol.for("react.fragment")) {
137
557
  // Handle Fragment as an empty props object
@@ -140,13 +560,21 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
140
560
  console.error("Unsupported symbol:", String(jsx));
141
561
  throw new Error(`Unsupported symbol: ${String(jsx)}`);
142
562
  } else if (typeof jsx === "object") {
563
+ if (isLayoutChildrenPlaceholder(jsx)) {
564
+ return jsx;
565
+ }
143
566
  if (jsx.$$typeof === Symbol.for("react.transitional.element")) {
144
567
  if (jsx.type === Symbol.for("react.suspense")) {
145
568
  if (isPprBuildActive()) {
146
569
  return await runInSuspense(async (holeId, suspenseStore) => {
147
570
  const countBefore = getPprHoleCounter();
148
571
  try {
149
- const renderedChildren = await asyncRenderJSXToClientJSX(jsx.props?.children);
572
+ const renderedChildren = isInsideCachedSlot()
573
+ ? await asyncRenderJSXToClientJSX(jsx.props?.children)
574
+ : await runInRuntimeDynamicHole(
575
+ () => asyncRenderJSXToClientJSX(jsx.props?.children),
576
+ holeId
577
+ );
150
578
  const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
151
579
  const hasNestedSuspense = getPprHoleCounter() > countBefore;
152
580
  await commitPprSuspenseEffects(suspenseStore);
@@ -195,10 +623,54 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
195
623
  }
196
624
  });
197
625
  }
198
- return await runInSuspense(async () => {
626
+ if (isInsideCachedSlot()) {
627
+ return await runInSuspense(async () => {
628
+ return cloneWithDevProps(
629
+ jsx,
630
+ await asyncRenderJSXToClientJSX(jsx.props),
631
+ key ?? jsx.key
632
+ );
633
+ });
634
+ }
635
+ const shouldEagerlyResolveSuspense =
636
+ Boolean(getPprStore()) ||
637
+ Boolean(getActiveRuntimeDynamicHoleStore()) ||
638
+ Boolean(getContext()?.platformContext?.isSSG) ||
639
+ process.env.NODE_ENV === "production" ||
640
+ containsCacheSlot(jsx.props?.children);
641
+ if (shouldEagerlyResolveSuspense) {
642
+ return await runInSuspense(async (holeId) => {
643
+ const renderedChildren = await runInRuntimeDynamicHole(
644
+ () => asyncRenderJSXToClientJSX(jsx.props?.children),
645
+ holeId
646
+ );
647
+ const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
648
+ return cloneWithDevProps(
649
+ jsx,
650
+ {
651
+ ...jsx.props,
652
+ children: renderedChildren,
653
+ fallback: renderedFallback,
654
+ },
655
+ key ?? jsx.key
656
+ );
657
+ });
658
+ }
659
+ if (jsx.props?.children?.type === DinouSuspenseHoleBoundary) {
660
+ return jsx;
661
+ }
662
+ return await runInSuspense(async (holeId) => {
663
+ const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
199
664
  return cloneWithDevProps(
200
665
  jsx,
201
- await asyncRenderJSXToClientJSX(jsx.props),
666
+ {
667
+ ...jsx.props,
668
+ children: React.createElement(DinouSuspenseHoleBoundary, {
669
+ holeId,
670
+ children: jsx.props?.children,
671
+ }),
672
+ fallback: renderedFallback,
673
+ },
202
674
  key ?? jsx.key
203
675
  );
204
676
  });
@@ -230,6 +702,8 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
230
702
  key ?? jsx.key,
231
703
  Component
232
704
  );
705
+ } else if (Component.$$dinouDeferredSuspenseStream) {
706
+ return jsx;
233
707
  } else {
234
708
  // Server component: execute and process
235
709
  const returnedJsx = await invokeServerComponentInPpr(Component, () =>
@@ -270,13 +744,19 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
270
744
  );
271
745
  } else {
272
746
  const innerComp = jsx.type.type;
273
- const returnedJsx =
274
- typeof innerComp === "function"
275
- ? await invokeServerComponentInPpr(innerComp, () =>
276
- innerComp(jsx.props)
277
- )
278
- : null;
279
- return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
747
+ if (typeof innerComp === "function") {
748
+ const returnedJsx = await invokeServerComponentInPpr(innerComp, () =>
749
+ innerComp(jsx.props)
750
+ );
751
+ return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
752
+ }
753
+ if (typeof innerComp === "object" && innerComp !== null) {
754
+ return await asyncRenderJSXToClientJSX(
755
+ cloneWithDevProps(jsx, jsx.props, key ?? jsx.key, innerComp),
756
+ key ?? jsx.key
757
+ );
758
+ }
759
+ return null;
280
760
  }
281
761
  } else {
282
762
  console.error("Unsupported JSX type:", jsx.type);
@@ -286,21 +766,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
286
766
  return jsx;
287
767
  } else {
288
768
  // Process object props (e.g., { className: "foo" })
289
- if (isPprBuildActive()) {
290
- const entries = [];
291
- for (const [propName, value] of Object.entries(jsx)) {
292
- entries.push([propName, await asyncRenderJSXToClientJSX(value)]);
293
- }
294
- return Object.fromEntries(entries);
769
+ const entries = [];
770
+ for (const [propName, value] of Object.entries(jsx)) {
771
+ entries.push([propName, await asyncRenderJSXToClientJSX(value)]);
295
772
  }
296
- return Object.fromEntries(
297
- await Promise.all(
298
- Object.entries(jsx).map(async ([propName, value]) => [
299
- propName,
300
- await asyncRenderJSXToClientJSX(value),
301
- ])
302
- )
303
- );
773
+ return Object.fromEntries(entries);
304
774
  }
305
775
  } else {
306
776
  throw new Error("Not implemented");
@@ -309,7 +779,13 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
309
779
 
310
780
  export {
311
781
  asyncRenderJSXToClientJSX,
782
+ invokeWithServerHooksDispatcher,
783
+ ensureServerHooksPatched,
784
+ replaceLayoutChildrenPlaceholder,
312
785
  };
313
786
  export default {
314
787
  asyncRenderJSXToClientJSX,
788
+ invokeWithServerHooksDispatcher,
789
+ ensureServerHooksPatched,
790
+ replaceLayoutChildrenPlaceholder,
315
791
  };