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 +13 -0
- package/README.md +1 -1
- package/dinou/cli.js +1 -1
- package/dinou/core/cache-slot.js +28 -16
- package/dinou/core/get-jsx.js +75 -7
- package/dinou/core/handler.js +5 -2
- package/dinou/core/ppr-context.js +122 -10
- package/dinou/core/ppr-runtime.js +68 -11
- package/dinou/core/render-jsx-to-client-jsx.js +516 -55
- package/dinou/core/rsc-renderer.js +3 -0
- 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/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
|
@@ -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 &&
|
|
@@ -33,24 +364,51 @@ function isCacheSlotComponent(fn) {
|
|
|
33
364
|
}
|
|
34
365
|
|
|
35
366
|
async function invokeServerComponentInPpr(fn, callFn) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
isThenable(rawResult) &&
|
|
41
|
-
!isCacheSlotComponent(fn) &&
|
|
42
|
-
isPprBuildActive() &&
|
|
43
|
-
isInsideOuterSuspenseOutsideSlot() &&
|
|
44
|
-
!isSlotDiscoveryActive() &&
|
|
45
|
-
!optedOut &&
|
|
46
|
-
!isNoDynamicActive()
|
|
47
|
-
) {
|
|
367
|
+
while (true) {
|
|
368
|
+
resetComponentNoDynamicFlag();
|
|
369
|
+
const idSnap = snapshotActiveIdCounts();
|
|
370
|
+
let rawResult;
|
|
48
371
|
try {
|
|
49
|
-
rawResult
|
|
50
|
-
} catch (
|
|
51
|
-
|
|
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;
|
|
52
411
|
}
|
|
53
|
-
return await rawResult;
|
|
54
412
|
}
|
|
55
413
|
|
|
56
414
|
function cloneWithDevProps(jsx, newProps, resolvedKey, overrideType) {
|
|
@@ -80,6 +438,54 @@ function cloneWithDevProps(jsx, newProps, resolvedKey, overrideType) {
|
|
|
80
438
|
return cloned;
|
|
81
439
|
}
|
|
82
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
|
+
|
|
83
489
|
// Function to check if a component is a client component
|
|
84
490
|
function isClientComponent(type) {
|
|
85
491
|
if (!type) {
|
|
@@ -92,17 +498,29 @@ function isClientComponent(type) {
|
|
|
92
498
|
);
|
|
93
499
|
}
|
|
94
500
|
|
|
501
|
+
async function DinouSuspenseHoleBoundary({ holeId, children }) {
|
|
502
|
+
return await runInRuntimeDynamicHole(
|
|
503
|
+
() => asyncRenderJSXToClientJSX(children),
|
|
504
|
+
holeId
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
95
508
|
async function asyncRenderJSXToClientJSX(jsx, key = null) {
|
|
96
509
|
if (isPageRootElement(jsx)) {
|
|
97
510
|
return await runInPageSegment(async () => {
|
|
98
511
|
const resolved = await asyncRenderJSXToClientJSXInner(jsx, key);
|
|
99
512
|
const ctx = getContext();
|
|
100
|
-
if (ctx) {
|
|
513
|
+
if (ctx && getPprStore()) {
|
|
101
514
|
ctx._resolvedPageClientJsx = resolved;
|
|
102
515
|
}
|
|
103
516
|
return resolved;
|
|
104
517
|
});
|
|
105
518
|
}
|
|
519
|
+
if (isLayoutRootElement(jsx)) {
|
|
520
|
+
return await runInLayoutSegment(async () => {
|
|
521
|
+
return await asyncRenderJSXToClientJSXInner(jsx, key);
|
|
522
|
+
});
|
|
523
|
+
}
|
|
106
524
|
return await asyncRenderJSXToClientJSXInner(jsx, key);
|
|
107
525
|
}
|
|
108
526
|
|
|
@@ -117,21 +535,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
117
535
|
) {
|
|
118
536
|
return jsx;
|
|
119
537
|
} else if (Array.isArray(jsx)) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
results.push(await asyncRenderJSXToClientJSX(child, child?.key ?? null));
|
|
124
|
-
}
|
|
125
|
-
return results;
|
|
538
|
+
const results = [];
|
|
539
|
+
for (const child of jsx) {
|
|
540
|
+
results.push(await asyncRenderJSXToClientJSX(child, child?.key ?? null));
|
|
126
541
|
}
|
|
127
|
-
return
|
|
128
|
-
jsx.map((child) =>
|
|
129
|
-
asyncRenderJSXToClientJSX(
|
|
130
|
-
child,
|
|
131
|
-
child?.key ?? null
|
|
132
|
-
)
|
|
133
|
-
)
|
|
134
|
-
);
|
|
542
|
+
return results;
|
|
135
543
|
} else if (typeof jsx === "symbol") {
|
|
136
544
|
if (jsx === Symbol.for("react.fragment")) {
|
|
137
545
|
// Handle Fragment as an empty props object
|
|
@@ -140,13 +548,21 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
140
548
|
console.error("Unsupported symbol:", String(jsx));
|
|
141
549
|
throw new Error(`Unsupported symbol: ${String(jsx)}`);
|
|
142
550
|
} else if (typeof jsx === "object") {
|
|
551
|
+
if (isLayoutChildrenPlaceholder(jsx)) {
|
|
552
|
+
return jsx;
|
|
553
|
+
}
|
|
143
554
|
if (jsx.$$typeof === Symbol.for("react.transitional.element")) {
|
|
144
555
|
if (jsx.type === Symbol.for("react.suspense")) {
|
|
145
556
|
if (isPprBuildActive()) {
|
|
146
557
|
return await runInSuspense(async (holeId, suspenseStore) => {
|
|
147
558
|
const countBefore = getPprHoleCounter();
|
|
148
559
|
try {
|
|
149
|
-
const renderedChildren =
|
|
560
|
+
const renderedChildren = isInsideCachedSlot()
|
|
561
|
+
? await asyncRenderJSXToClientJSX(jsx.props?.children)
|
|
562
|
+
: await runInRuntimeDynamicHole(
|
|
563
|
+
() => asyncRenderJSXToClientJSX(jsx.props?.children),
|
|
564
|
+
holeId
|
|
565
|
+
);
|
|
150
566
|
const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
|
|
151
567
|
const hasNestedSuspense = getPprHoleCounter() > countBefore;
|
|
152
568
|
await commitPprSuspenseEffects(suspenseStore);
|
|
@@ -195,10 +611,53 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
195
611
|
}
|
|
196
612
|
});
|
|
197
613
|
}
|
|
198
|
-
|
|
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);
|
|
199
651
|
return cloneWithDevProps(
|
|
200
652
|
jsx,
|
|
201
|
-
|
|
653
|
+
{
|
|
654
|
+
...jsx.props,
|
|
655
|
+
children: React.createElement(DinouSuspenseHoleBoundary, {
|
|
656
|
+
holeId,
|
|
657
|
+
children: jsx.props?.children,
|
|
658
|
+
}),
|
|
659
|
+
fallback: renderedFallback,
|
|
660
|
+
},
|
|
202
661
|
key ?? jsx.key
|
|
203
662
|
);
|
|
204
663
|
});
|
|
@@ -270,13 +729,19 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
270
729
|
);
|
|
271
730
|
} else {
|
|
272
731
|
const innerComp = jsx.type.type;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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;
|
|
280
745
|
}
|
|
281
746
|
} else {
|
|
282
747
|
console.error("Unsupported JSX type:", jsx.type);
|
|
@@ -286,21 +751,11 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
286
751
|
return jsx;
|
|
287
752
|
} else {
|
|
288
753
|
// Process object props (e.g., { className: "foo" })
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
entries.push([propName, await asyncRenderJSXToClientJSX(value)]);
|
|
293
|
-
}
|
|
294
|
-
return Object.fromEntries(entries);
|
|
754
|
+
const entries = [];
|
|
755
|
+
for (const [propName, value] of Object.entries(jsx)) {
|
|
756
|
+
entries.push([propName, await asyncRenderJSXToClientJSX(value)]);
|
|
295
757
|
}
|
|
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
|
-
);
|
|
758
|
+
return Object.fromEntries(entries);
|
|
304
759
|
}
|
|
305
760
|
} else {
|
|
306
761
|
throw new Error("Not implemented");
|
|
@@ -309,7 +764,13 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
309
764
|
|
|
310
765
|
export {
|
|
311
766
|
asyncRenderJSXToClientJSX,
|
|
767
|
+
invokeWithServerHooksDispatcher,
|
|
768
|
+
ensureServerHooksPatched,
|
|
769
|
+
replaceLayoutChildrenPlaceholder,
|
|
312
770
|
};
|
|
313
771
|
export default {
|
|
314
772
|
asyncRenderJSXToClientJSX,
|
|
773
|
+
invokeWithServerHooksDispatcher,
|
|
774
|
+
ensureServerHooksPatched,
|
|
775
|
+
replaceLayoutChildrenPlaceholder,
|
|
315
776
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
+
import { ensureServerHooksPatched } from "./render-jsx-to-client-jsx.js";
|
|
6
7
|
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
8
9
|
|
|
@@ -55,6 +56,8 @@ function getEdgeRenderer() {
|
|
|
55
56
|
* @returns {ReadableStream | { pipe: Function, abort: Function }}
|
|
56
57
|
*/
|
|
57
58
|
function renderRSCStream(model, manifest, options = {}) {
|
|
59
|
+
ensureServerHooksPatched();
|
|
60
|
+
|
|
58
61
|
if (isEdgeRuntime(options)) {
|
|
59
62
|
const edge = getEdgeRenderer();
|
|
60
63
|
const clientManifest =
|