dinou 9.0.3 → 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.
@@ -1,14 +1,416 @@
1
1
  import React from "react";
2
+ import { createRequire } from "node:module";
2
3
  import {
3
4
  isPprBuildActive,
5
+ getPprStore,
6
+ isInsideSuspense,
7
+ isInsideOuterSuspenseOutsideSlot,
8
+ rollbackPprHolesAfter,
9
+ isInsideCachedSlot,
10
+ getActiveCachedSlotStore,
11
+ getActiveRuntimeDynamicHoleStore,
12
+ runInRuntimeDynamicHole,
4
13
  runInSuspense,
14
+ getPprHoleCounter,
5
15
  commitPprSuspenseEffects,
6
16
  registerHole,
17
+ markDynamicAccess,
7
18
  isPageRootElement,
19
+ isLayoutRootElement,
20
+ isLayoutChildrenPlaceholder,
8
21
  runInPageSegment,
22
+ runInLayoutSegment,
23
+ getActivePageSegmentStore,
24
+ getActiveLayoutSegmentStore,
25
+ resetComponentNoDynamicFlag,
26
+ consumeComponentNoDynamicFlag,
27
+ isNoDynamicActive,
28
+ isSlotDiscoveryActive,
9
29
  } from "./ppr-context.js";
10
30
  import { getContext } from "./request-context.js";
11
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
+
353
+ function isThenable(val) {
354
+ return (
355
+ val !== null &&
356
+ (typeof val === "object" || typeof val === "function") &&
357
+ typeof val.then === "function"
358
+ );
359
+ }
360
+
361
+ function isCacheSlotComponent(fn) {
362
+ if (!fn) return false;
363
+ return Boolean(fn.$$dinouCacheSlot || fn.name === "DinouCacheSlot");
364
+ }
365
+
366
+ async function invokeServerComponentInPpr(fn, callFn) {
367
+ while (true) {
368
+ resetComponentNoDynamicFlag();
369
+ const idSnap = snapshotActiveIdCounts();
370
+ let rawResult;
371
+ try {
372
+ rawResult = invokeWithServerHooksDispatcher(callFn);
373
+ } catch (thrown) {
374
+ restoreActiveIdCounts(idSnap);
375
+ const optedOutOnThrow = consumeComponentNoDynamicFlag();
376
+ if (isThenable(thrown)) {
377
+ if (
378
+ !isCacheSlotComponent(fn) &&
379
+ isPprBuildActive() &&
380
+ isInsideOuterSuspenseOutsideSlot() &&
381
+ !isSlotDiscoveryActive() &&
382
+ !optedOutOnThrow &&
383
+ !isNoDynamicActive()
384
+ ) {
385
+ try {
386
+ thrown.then(null, () => {});
387
+ } catch (_) {}
388
+ markDynamicAccess("async-suspense");
389
+ }
390
+ await thrown;
391
+ continue;
392
+ }
393
+ throw thrown;
394
+ }
395
+ const optedOut = consumeComponentNoDynamicFlag();
396
+ if (
397
+ isThenable(rawResult) &&
398
+ !isCacheSlotComponent(fn) &&
399
+ isPprBuildActive() &&
400
+ isInsideOuterSuspenseOutsideSlot() &&
401
+ !isSlotDiscoveryActive() &&
402
+ !optedOut &&
403
+ !isNoDynamicActive()
404
+ ) {
405
+ try {
406
+ rawResult.then(null, () => {});
407
+ } catch (_) {}
408
+ markDynamicAccess("async-suspense");
409
+ }
410
+ return await rawResult;
411
+ }
412
+ }
413
+
12
414
  function cloneWithDevProps(jsx, newProps, resolvedKey, overrideType) {
13
415
  const cloned = {
14
416
  ...jsx,
@@ -36,6 +438,54 @@ function cloneWithDevProps(jsx, newProps, resolvedKey, overrideType) {
36
438
  return cloned;
37
439
  }
38
440
 
441
+ function replaceLayoutChildrenPlaceholder(node, replacement, placeholder) {
442
+ if (node == null || typeof node !== "object") return node;
443
+ if (node === placeholder || isLayoutChildrenPlaceholder(node)) {
444
+ return replacement;
445
+ }
446
+ if (Array.isArray(node)) {
447
+ let changed = false;
448
+ const mapped = node.map((item) => {
449
+ const updated = replaceLayoutChildrenPlaceholder(item, replacement, placeholder);
450
+ if (updated !== item) changed = true;
451
+ return updated;
452
+ });
453
+ return changed ? mapped : node;
454
+ }
455
+ if (node.$$typeof === Symbol.for("react.transitional.element")) {
456
+ if (node.props && typeof node.props === "object") {
457
+ let changed = false;
458
+ const newProps = { ...node.props };
459
+ for (const [k, v] of Object.entries(node.props)) {
460
+ if (v && typeof v === "object") {
461
+ const updated = replaceLayoutChildrenPlaceholder(v, replacement, placeholder);
462
+ if (updated !== v) {
463
+ newProps[k] = updated;
464
+ changed = true;
465
+ }
466
+ }
467
+ }
468
+ if (changed) {
469
+ return cloneWithDevProps(node, newProps, node.key);
470
+ }
471
+ }
472
+ return node;
473
+ }
474
+ if (node instanceof Promise) return node;
475
+ let changed = false;
476
+ const clone = { ...node };
477
+ for (const [k, v] of Object.entries(node)) {
478
+ if (v && typeof v === "object") {
479
+ const updated = replaceLayoutChildrenPlaceholder(v, replacement, placeholder);
480
+ if (updated !== v) {
481
+ clone[k] = updated;
482
+ changed = true;
483
+ }
484
+ }
485
+ }
486
+ return changed ? clone : node;
487
+ }
488
+
39
489
  // Function to check if a component is a client component
40
490
  function isClientComponent(type) {
41
491
  if (!type) {
@@ -48,17 +498,29 @@ function isClientComponent(type) {
48
498
  );
49
499
  }
50
500
 
501
+ async function DinouSuspenseHoleBoundary({ holeId, children }) {
502
+ return await runInRuntimeDynamicHole(
503
+ () => asyncRenderJSXToClientJSX(children),
504
+ holeId
505
+ );
506
+ }
507
+
51
508
  async function asyncRenderJSXToClientJSX(jsx, key = null) {
52
509
  if (isPageRootElement(jsx)) {
53
510
  return await runInPageSegment(async () => {
54
511
  const resolved = await asyncRenderJSXToClientJSXInner(jsx, key);
55
512
  const ctx = getContext();
56
- if (ctx) {
513
+ if (ctx && getPprStore()) {
57
514
  ctx._resolvedPageClientJsx = resolved;
58
515
  }
59
516
  return resolved;
60
517
  });
61
518
  }
519
+ if (isLayoutRootElement(jsx)) {
520
+ return await runInLayoutSegment(async () => {
521
+ return await asyncRenderJSXToClientJSXInner(jsx, key);
522
+ });
523
+ }
62
524
  return await asyncRenderJSXToClientJSXInner(jsx, key);
63
525
  }
64
526
 
@@ -73,21 +535,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
73
535
  ) {
74
536
  return jsx;
75
537
  } else if (Array.isArray(jsx)) {
76
- if (isPprBuildActive()) {
77
- const results = [];
78
- for (const child of jsx) {
79
- results.push(await asyncRenderJSXToClientJSX(child, child?.key ?? null));
80
- }
81
- return results;
82
- }
83
- return await Promise.all(
84
- jsx.map((child) =>
85
- asyncRenderJSXToClientJSX(
86
- child,
87
- child?.key ?? null
88
- )
89
- )
90
- );
538
+ const results = [];
539
+ for (const child of jsx) {
540
+ results.push(await asyncRenderJSXToClientJSX(child, child?.key ?? null));
541
+ }
542
+ return results;
91
543
  } else if (typeof jsx === "symbol") {
92
544
  if (jsx === Symbol.for("react.fragment")) {
93
545
  // Handle Fragment as an empty props object
@@ -96,29 +548,48 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
96
548
  console.error("Unsupported symbol:", String(jsx));
97
549
  throw new Error(`Unsupported symbol: ${String(jsx)}`);
98
550
  } else if (typeof jsx === "object") {
551
+ if (isLayoutChildrenPlaceholder(jsx)) {
552
+ return jsx;
553
+ }
99
554
  if (jsx.$$typeof === Symbol.for("react.transitional.element")) {
100
555
  if (jsx.type === Symbol.for("react.suspense")) {
101
556
  if (isPprBuildActive()) {
102
557
  return await runInSuspense(async (holeId, suspenseStore) => {
558
+ const countBefore = getPprHoleCounter();
103
559
  try {
104
- const renderedChildren = await asyncRenderJSXToClientJSX(jsx.props?.children);
560
+ const renderedChildren = isInsideCachedSlot()
561
+ ? await asyncRenderJSXToClientJSX(jsx.props?.children)
562
+ : await runInRuntimeDynamicHole(
563
+ () => asyncRenderJSXToClientJSX(jsx.props?.children),
564
+ holeId
565
+ );
105
566
  const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
567
+ const hasNestedSuspense = getPprHoleCounter() > countBefore;
106
568
  await commitPprSuspenseEffects(suspenseStore);
107
569
  return cloneWithDevProps(
108
570
  jsx,
109
571
  {
110
572
  ...jsx.props,
111
- children: renderedChildren,
573
+ ...(hasNestedSuspense ? { "data-ppr-static-parent": holeId } : {}),
574
+ children: hasNestedSuspense
575
+ ? React.createElement(
576
+ "div",
577
+ { "data-ppr-static-parent": holeId, style: { display: "contents" } },
578
+ renderedChildren
579
+ )
580
+ : renderedChildren,
112
581
  fallback: renderedFallback,
113
582
  },
114
583
  key ?? jsx.key
115
584
  );
116
585
  } catch (err) {
117
586
  if (
118
- (err && err.$$typeof === Symbol.for("dinou.ppr.postpone")) ||
119
- (err && typeof err?.then === "function") ||
120
- (err && err?.$$typeof === Symbol.for("react.postpone"))
587
+ (suspenseStore?.slotDepthAtSuspense || 0) === 0 &&
588
+ ((err && err.$$typeof === Symbol.for("dinou.ppr.postpone")) ||
589
+ (err && typeof err?.then === "function") ||
590
+ (err && err?.$$typeof === Symbol.for("react.postpone")))
121
591
  ) {
592
+ rollbackPprHolesAfter(countBefore);
122
593
  registerHole(holeId, { type: err.pprType || "suspense" });
123
594
  const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
124
595
  return cloneWithDevProps(
@@ -133,14 +604,63 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
133
604
  );
134
605
  }
135
606
  throw err;
607
+ } finally {
608
+ if (suspenseStore) {
609
+ suspenseStore.settled = true;
610
+ }
136
611
  }
137
612
  });
138
613
  }
139
- return cloneWithDevProps(
140
- jsx,
141
- await asyncRenderJSXToClientJSX(jsx.props),
142
- key ?? jsx.key
143
- );
614
+ if (isInsideCachedSlot()) {
615
+ return await runInSuspense(async () => {
616
+ return cloneWithDevProps(
617
+ jsx,
618
+ await asyncRenderJSXToClientJSX(jsx.props),
619
+ key ?? jsx.key
620
+ );
621
+ });
622
+ }
623
+ const shouldEagerlyResolveSuspense =
624
+ Boolean(getPprStore()) ||
625
+ Boolean(getActiveRuntimeDynamicHoleStore()) ||
626
+ Boolean(getContext()?.platformContext?.isSSG) ||
627
+ process.env.NODE_ENV === "production";
628
+ if (shouldEagerlyResolveSuspense) {
629
+ return await runInSuspense(async (holeId) => {
630
+ const renderedChildren = await runInRuntimeDynamicHole(
631
+ () => asyncRenderJSXToClientJSX(jsx.props?.children),
632
+ holeId
633
+ );
634
+ const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
635
+ return cloneWithDevProps(
636
+ jsx,
637
+ {
638
+ ...jsx.props,
639
+ children: renderedChildren,
640
+ fallback: renderedFallback,
641
+ },
642
+ key ?? jsx.key
643
+ );
644
+ });
645
+ }
646
+ if (jsx.props?.children?.type === DinouSuspenseHoleBoundary) {
647
+ return jsx;
648
+ }
649
+ return await runInSuspense(async (holeId) => {
650
+ const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
651
+ return cloneWithDevProps(
652
+ jsx,
653
+ {
654
+ ...jsx.props,
655
+ children: React.createElement(DinouSuspenseHoleBoundary, {
656
+ holeId,
657
+ children: jsx.props?.children,
658
+ }),
659
+ fallback: renderedFallback,
660
+ },
661
+ key ?? jsx.key
662
+ );
663
+ });
144
664
  } else if (
145
665
  jsx.type === Symbol.for("react.fragment") ||
146
666
  jsx.type === Symbol.for("react.view_transition") ||
@@ -171,7 +691,9 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
171
691
  );
172
692
  } else {
173
693
  // Server component: execute and process
174
- const returnedJsx = await Component(props);
694
+ const returnedJsx = await invokeServerComponentInPpr(Component, () =>
695
+ Component(props)
696
+ );
175
697
  return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
176
698
  }
177
699
  } else if (
@@ -187,7 +709,10 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
187
709
  jsx.type
188
710
  );
189
711
  } else {
190
- const returnedJsx = await jsx.type.render(jsx.props, jsx.ref);
712
+ const returnedJsx = await invokeServerComponentInPpr(
713
+ jsx.type.render,
714
+ () => jsx.type.render(jsx.props, jsx.ref)
715
+ );
191
716
  return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
192
717
  }
193
718
  } else if (
@@ -204,8 +729,19 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
204
729
  );
205
730
  } else {
206
731
  const innerComp = jsx.type.type;
207
- const returnedJsx = typeof innerComp === "function" ? await innerComp(jsx.props) : null;
208
- return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
732
+ if (typeof innerComp === "function") {
733
+ const returnedJsx = await invokeServerComponentInPpr(innerComp, () =>
734
+ innerComp(jsx.props)
735
+ );
736
+ return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
737
+ }
738
+ if (typeof innerComp === "object" && innerComp !== null) {
739
+ return await asyncRenderJSXToClientJSX(
740
+ cloneWithDevProps(jsx, jsx.props, key ?? jsx.key, innerComp),
741
+ key ?? jsx.key
742
+ );
743
+ }
744
+ return null;
209
745
  }
210
746
  } else {
211
747
  console.error("Unsupported JSX type:", jsx.type);
@@ -215,21 +751,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
215
751
  return jsx;
216
752
  } else {
217
753
  // Process object props (e.g., { className: "foo" })
218
- if (isPprBuildActive()) {
219
- const entries = [];
220
- for (const [propName, value] of Object.entries(jsx)) {
221
- entries.push([propName, await asyncRenderJSXToClientJSX(value)]);
222
- }
223
- return Object.fromEntries(entries);
754
+ const entries = [];
755
+ for (const [propName, value] of Object.entries(jsx)) {
756
+ entries.push([propName, await asyncRenderJSXToClientJSX(value)]);
224
757
  }
225
- return Object.fromEntries(
226
- await Promise.all(
227
- Object.entries(jsx).map(async ([propName, value]) => [
228
- propName,
229
- await asyncRenderJSXToClientJSX(value),
230
- ])
231
- )
232
- );
758
+ return Object.fromEntries(entries);
233
759
  }
234
760
  } else {
235
761
  throw new Error("Not implemented");
@@ -238,7 +764,13 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
238
764
 
239
765
  export {
240
766
  asyncRenderJSXToClientJSX,
767
+ invokeWithServerHooksDispatcher,
768
+ ensureServerHooksPatched,
769
+ replaceLayoutChildrenPlaceholder,
241
770
  };
242
771
  export default {
243
772
  asyncRenderJSXToClientJSX,
773
+ invokeWithServerHooksDispatcher,
774
+ ensureServerHooksPatched,
775
+ replaceLayoutChildrenPlaceholder,
244
776
  };