dinou 9.0.2 → 9.1.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 +65 -0
- package/README.md +379 -9742
- package/dinou/bun/build.js +38 -1
- package/{cli.js → dinou/cli.js} +8 -7
- package/dinou/cloudflare/build.js +37 -0
- package/dinou/core/bailout-proxy.js +2 -2
- package/dinou/core/build-static-pages.js +17 -7
- package/dinou/core/cache-revalidate.js +977 -152
- package/dinou/core/cache-slot.js +848 -103
- package/dinou/core/client-webpack.jsx +60 -9
- package/dinou/core/client.jsx +60 -9
- package/dinou/core/edge-ssr.js +33 -5
- package/dinou/core/generate-static.js +109 -47
- package/dinou/core/get-jsx.js +35 -27
- package/dinou/core/handler.js +786 -54
- package/dinou/core/layout-functions.js +102 -1
- package/dinou/core/no-dynamic.js +25 -0
- package/dinou/core/ppr-context.js +293 -10
- package/dinou/core/ppr-runtime.js +373 -37
- package/dinou/core/render-jsx-to-client-jsx.js +205 -74
- package/dinou/core/slot.js +246 -33
- package/dinou/core/storage-adapter.js +117 -11
- package/dinou/deno/build.js +38 -1
- package/dinou/deno/seed-kv.js +43 -11
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +242 -225
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +253 -226
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +209 -209
- package/dinou/index.d.ts +10 -0
- package/dinou/index.js +3 -0
- package/dinou/node/build.js +2 -2
- package/dinou/node/bundle-dual-engine.js +2 -0
- package/dinou/node/dev.js +2853 -2704
- package/dinou/package.json +4 -1
- package/dinou/rollup/react-refresh/esm-hmr/client.js +220 -220
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +182 -160
- package/dinou/server.d.ts +65 -12
- package/dinou/server.js +11 -0
- package/dinou/webpack/loaders/server-functions-loader.js +101 -94
- package/dinou/webpack/webpack.config.js +9 -4
- package/eject.js +219 -223
- package/package.json +2 -2
|
@@ -9,13 +9,252 @@ 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
|
+
SKIP_STATIC_SUSPENSE_SYMBOL,
|
|
14
|
+
runInRuntimeStaticSuspense,
|
|
15
|
+
runInRuntimeDynamicHole,
|
|
16
|
+
} from "./ppr-context.js";
|
|
17
|
+
|
|
18
|
+
function escapeHtml(str) {
|
|
19
|
+
return String(str)
|
|
20
|
+
.replace(/&/g, "&")
|
|
21
|
+
.replace(/</g, "<")
|
|
22
|
+
.replace(/>/g, ">")
|
|
23
|
+
.replace(/"/g, """)
|
|
24
|
+
.replace(/'/g, "'");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isClientComponentRef(type) {
|
|
28
|
+
if (!type) return false;
|
|
29
|
+
return (
|
|
30
|
+
type.$$typeof === Symbol.for("react.client.reference") ||
|
|
31
|
+
Boolean(type.$$id) ||
|
|
32
|
+
Boolean(type.filepath)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Splices live dynamic <Suspense> subtrees from a live page evaluation into a
|
|
38
|
+
* cached PPR static shell client-JSX tree (deserialized from shell.page.json),
|
|
39
|
+
* keeping the static shell of the page 100% immutable across /____rsc_page____
|
|
40
|
+
* refreshes and soft-navigations while evaluating dynamic holes fresh.
|
|
41
|
+
*/
|
|
42
|
+
async function spliceDynamicHolesIntoShell(
|
|
43
|
+
cachedShellTree,
|
|
44
|
+
livePageNodeOrFn,
|
|
45
|
+
startHoleIndex = 0
|
|
46
|
+
) {
|
|
47
|
+
const knownHoleIds = new Set();
|
|
48
|
+
const staticParentHoleIds = new Set();
|
|
49
|
+
function collectKnownHoles(node) {
|
|
50
|
+
if (!node || typeof node !== "object") return;
|
|
51
|
+
if (Array.isArray(node)) {
|
|
52
|
+
for (const item of node) collectKnownHoles(item);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (node.$$typeof === Symbol.for("react.transitional.element")) {
|
|
56
|
+
if (node.props && typeof node.props["data-ppr-hole"] === "string") {
|
|
57
|
+
knownHoleIds.add(node.props["data-ppr-hole"]);
|
|
58
|
+
}
|
|
59
|
+
if (node.props && typeof node.props["data-ppr-static-parent"] === "string") {
|
|
60
|
+
staticParentHoleIds.add(node.props["data-ppr-static-parent"]);
|
|
61
|
+
}
|
|
62
|
+
if (node.props && typeof node.props === "object") {
|
|
63
|
+
for (const val of Object.values(node.props)) {
|
|
64
|
+
if (val && typeof val === "object") collectKnownHoles(val);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
for (const val of Object.values(node)) {
|
|
69
|
+
if (val && typeof val === "object") collectKnownHoles(val);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
collectKnownHoles(cachedShellTree);
|
|
75
|
+
if (knownHoleIds.size === 0) {
|
|
76
|
+
return cachedShellTree;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const livePageNode =
|
|
80
|
+
typeof livePageNodeOrFn === "function"
|
|
81
|
+
? await livePageNodeOrFn()
|
|
82
|
+
: livePageNodeOrFn;
|
|
83
|
+
|
|
84
|
+
let holeIndex = Number(startHoleIndex) || 0;
|
|
85
|
+
const liveHolesMap = new Map();
|
|
86
|
+
|
|
87
|
+
async function traverseProps(props) {
|
|
88
|
+
if (!props || typeof props !== "object") return;
|
|
89
|
+
for (const [, value] of Object.entries(props)) {
|
|
90
|
+
if (value && typeof value === "object") {
|
|
91
|
+
await traverse(value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function traverse(current) {
|
|
97
|
+
if (!current || liveHolesMap.size >= knownHoleIds.size) return;
|
|
98
|
+
if (Array.isArray(current)) {
|
|
99
|
+
for (const item of current) {
|
|
100
|
+
if (liveHolesMap.size >= knownHoleIds.size) return;
|
|
101
|
+
await traverse(item);
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (typeof current !== "object" || current instanceof Promise) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (
|
|
109
|
+
isClientComponentRef(current?.type) ||
|
|
110
|
+
current?.$$typeof === Symbol.for("react.client.reference")
|
|
111
|
+
) {
|
|
112
|
+
await traverseProps(current?.props);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (typeof current?.type === "function") {
|
|
116
|
+
try {
|
|
117
|
+
const evaluated = await current.type(current.props || {});
|
|
118
|
+
await traverse(evaluated);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
console.error("[Dinou PPR] Error evaluating component in hole splice:", err);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (
|
|
128
|
+
typeof current?.type === "object" &&
|
|
129
|
+
current.type !== null &&
|
|
130
|
+
current.type.$$typeof === Symbol.for("react.forward_ref")
|
|
131
|
+
) {
|
|
132
|
+
if (isClientComponentRef(current.type)) {
|
|
133
|
+
await traverseProps(current.props);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
const rendered = await current.type.render(current.props || {}, current.ref);
|
|
138
|
+
await traverse(rendered);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
console.error("[Dinou PPR] Error evaluating forward_ref in hole splice:", err);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (
|
|
148
|
+
typeof current?.type === "object" &&
|
|
149
|
+
current.type !== null &&
|
|
150
|
+
current.type.$$typeof === Symbol.for("react.memo")
|
|
151
|
+
) {
|
|
152
|
+
if (isClientComponentRef(current.type)) {
|
|
153
|
+
await traverseProps(current.props);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const innerComp = current.type.type;
|
|
158
|
+
const rendered =
|
|
159
|
+
typeof innerComp === "function" ? await innerComp(current.props || {}) : null;
|
|
160
|
+
await traverse(rendered);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
console.error("[Dinou PPR] Error evaluating memo in hole splice:", err);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (
|
|
170
|
+
current?.type === Symbol.for("react.suspense") ||
|
|
171
|
+
current?.type === React.Suspense
|
|
172
|
+
) {
|
|
173
|
+
holeIndex++;
|
|
174
|
+
const currentHoleId = `ppr-hole-${holeIndex}`;
|
|
175
|
+
if (knownHoleIds.has(currentHoleId)) {
|
|
176
|
+
liveHolesMap.set(currentHoleId, current);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const runStaticScope = staticParentHoleIds.has(currentHoleId)
|
|
180
|
+
? runInRuntimeDynamicHole
|
|
181
|
+
: runInRuntimeStaticSuspense;
|
|
182
|
+
await runStaticScope(async () => {
|
|
183
|
+
if (current.props?.children) {
|
|
184
|
+
await traverse(current.props.children);
|
|
185
|
+
}
|
|
186
|
+
if (current.props?.fallback) {
|
|
187
|
+
await traverse(current.props.fallback);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (current?.$$typeof === Symbol.for("react.transitional.element")) {
|
|
193
|
+
await traverseProps(current.props);
|
|
194
|
+
} else {
|
|
195
|
+
await traverseProps(current);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
await traverse(livePageNode);
|
|
200
|
+
|
|
201
|
+
function replaceHoles(node) {
|
|
202
|
+
if (!node || typeof node !== "object") return node;
|
|
203
|
+
if (Array.isArray(node)) {
|
|
204
|
+
return node.map((item) => replaceHoles(item));
|
|
205
|
+
}
|
|
206
|
+
if (node.$$typeof === Symbol.for("react.transitional.element")) {
|
|
207
|
+
const holeId = node.props && node.props["data-ppr-hole"];
|
|
208
|
+
if (typeof holeId === "string" && liveHolesMap.has(holeId)) {
|
|
209
|
+
return liveHolesMap.get(holeId);
|
|
210
|
+
}
|
|
211
|
+
if (node.props && typeof node.props === "object") {
|
|
212
|
+
let changed = false;
|
|
213
|
+
const newProps = { ...node.props };
|
|
214
|
+
for (const [k, v] of Object.entries(node.props)) {
|
|
215
|
+
if (v && typeof v === "object") {
|
|
216
|
+
const updated = replaceHoles(v);
|
|
217
|
+
if (updated !== v) {
|
|
218
|
+
newProps[k] = updated;
|
|
219
|
+
changed = true;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (changed) {
|
|
224
|
+
if (node.key != null) newProps.key = node.key;
|
|
225
|
+
const children = newProps.children;
|
|
226
|
+
if (Array.isArray(children)) {
|
|
227
|
+
delete newProps.children;
|
|
228
|
+
return React.createElement(node.type, newProps, ...children);
|
|
229
|
+
}
|
|
230
|
+
return React.createElement(node.type, newProps);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return node;
|
|
234
|
+
}
|
|
235
|
+
let changed = false;
|
|
236
|
+
const clone = { ...node };
|
|
237
|
+
for (const [k, v] of Object.entries(node)) {
|
|
238
|
+
if (v && typeof v === "object") {
|
|
239
|
+
const updated = replaceHoles(v);
|
|
240
|
+
if (updated !== v) {
|
|
241
|
+
clone[k] = updated;
|
|
242
|
+
changed = true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return changed ? clone : node;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return replaceHoles(cachedShellTree);
|
|
250
|
+
}
|
|
12
251
|
|
|
13
252
|
/**
|
|
14
253
|
* Traverses a React JSX element tree to find Suspense boundaries,
|
|
15
254
|
* evaluates their dynamic children, and streams replacement chunks.
|
|
16
255
|
*
|
|
17
256
|
* @param {object} node - Root JSX node (layout + page)
|
|
18
|
-
* @param {Array<string|object
|
|
257
|
+
* @param {Array<string|object>|null} expectedHoles - Holes registered at build time
|
|
19
258
|
* @param {WritableStreamDefaultWriter} writer - Response stream writer
|
|
20
259
|
* @param {TextEncoder} encoder - Text encoder
|
|
21
260
|
* @param {object} platformContext - Dinou platform context (containing renderHtmlStream)
|
|
@@ -27,43 +266,66 @@ async function streamDynamicHoles(
|
|
|
27
266
|
writer,
|
|
28
267
|
encoder,
|
|
29
268
|
platformContext,
|
|
30
|
-
isDevelopment = false
|
|
269
|
+
isDevelopment = false,
|
|
270
|
+
staticParentHoles = null
|
|
31
271
|
) {
|
|
32
272
|
let holeIndex = 0;
|
|
33
273
|
const holePromises = [];
|
|
34
274
|
|
|
275
|
+
const hasExplicitHoles = Array.isArray(expectedHoles);
|
|
35
276
|
const knownHoleIds = new Set(
|
|
36
277
|
(expectedHoles || []).map((h) => (typeof h === "object" ? h.id : h))
|
|
37
278
|
);
|
|
279
|
+
if (hasExplicitHoles && knownHoleIds.size === 0) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
38
282
|
|
|
39
283
|
const clientManifest = getClientManifest();
|
|
40
284
|
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
285
|
+
async function traverseProps(props) {
|
|
286
|
+
if (!props || typeof props !== "object") return;
|
|
287
|
+
for (const [, value] of Object.entries(props)) {
|
|
288
|
+
if (hasExplicitHoles && holePromises.length >= knownHoleIds.size) return;
|
|
289
|
+
if (value && typeof value === "object") {
|
|
290
|
+
await traverse(value);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
49
294
|
|
|
50
295
|
async function traverse(current) {
|
|
51
|
-
if (!current) return;
|
|
296
|
+
if (!current || (hasExplicitHoles && holePromises.length >= knownHoleIds.size)) return;
|
|
52
297
|
|
|
53
|
-
// Handle
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
298
|
+
// Handle Arrays (children)
|
|
299
|
+
if (Array.isArray(current)) {
|
|
300
|
+
for (const item of current) {
|
|
301
|
+
if (hasExplicitHoles && holePromises.length >= knownHoleIds.size) return;
|
|
302
|
+
await traverse(item);
|
|
57
303
|
}
|
|
58
304
|
return;
|
|
59
305
|
}
|
|
60
306
|
|
|
307
|
+
if (typeof current !== "object" || current instanceof Promise) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Handle Client Component: do NOT execute, only traverse props in deterministic order
|
|
312
|
+
if (
|
|
313
|
+
isClientComponentRef(current?.type) ||
|
|
314
|
+
current?.$$typeof === Symbol.for("react.client.reference")
|
|
315
|
+
) {
|
|
316
|
+
await traverseProps(current?.props);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
61
320
|
// Handle React Server Component function
|
|
62
321
|
if (typeof current?.type === "function") {
|
|
63
322
|
try {
|
|
64
323
|
const evaluated = await current.type(current.props || {});
|
|
65
324
|
await traverse(evaluated);
|
|
66
325
|
} catch (err) {
|
|
326
|
+
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
67
329
|
console.error("[Dinou PPR] Error evaluating component in hole traversal:", err);
|
|
68
330
|
}
|
|
69
331
|
return;
|
|
@@ -75,30 +337,63 @@ function isClientComponent(type) {
|
|
|
75
337
|
current.type !== null &&
|
|
76
338
|
current.type.$$typeof === Symbol.for("react.forward_ref")
|
|
77
339
|
) {
|
|
340
|
+
if (isClientComponentRef(current.type)) {
|
|
341
|
+
await traverseProps(current.props);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
78
344
|
try {
|
|
79
|
-
const rendered = current.type.render(current.props || {}, current.ref);
|
|
345
|
+
const rendered = await current.type.render(current.props || {}, current.ref);
|
|
80
346
|
await traverse(rendered);
|
|
81
347
|
} catch (err) {
|
|
348
|
+
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
82
351
|
console.error("[Dinou PPR] Error evaluating forward_ref in hole traversal:", err);
|
|
83
352
|
}
|
|
84
353
|
return;
|
|
85
354
|
}
|
|
86
355
|
|
|
356
|
+
// Handle React.memo
|
|
357
|
+
if (
|
|
358
|
+
typeof current?.type === "object" &&
|
|
359
|
+
current.type !== null &&
|
|
360
|
+
current.type.$$typeof === Symbol.for("react.memo")
|
|
361
|
+
) {
|
|
362
|
+
if (isClientComponentRef(current.type)) {
|
|
363
|
+
await traverseProps(current.props);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
const innerComp = current.type.type;
|
|
368
|
+
const rendered =
|
|
369
|
+
typeof innerComp === "function" ? await innerComp(current.props || {}) : null;
|
|
370
|
+
await traverse(rendered);
|
|
371
|
+
} catch (err) {
|
|
372
|
+
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
console.error("[Dinou PPR] Error evaluating memo in hole traversal:", err);
|
|
376
|
+
}
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
87
380
|
// Handle React.Suspense
|
|
88
381
|
if (
|
|
89
382
|
current?.type === Symbol.for("react.suspense") ||
|
|
90
383
|
current?.type === React.Suspense
|
|
91
384
|
) {
|
|
92
385
|
holeIndex++;
|
|
386
|
+
const currentBoundaryIndex = holeIndex - 1;
|
|
93
387
|
const currentHoleId = `ppr-hole-${holeIndex}`;
|
|
94
388
|
|
|
95
|
-
// Check if this boundary was registered as a dynamic hole
|
|
96
|
-
const shouldStream =
|
|
97
|
-
|
|
389
|
+
// Check if this boundary was registered as a dynamic hole at build time
|
|
390
|
+
const shouldStream = hasExplicitHoles
|
|
391
|
+
? knownHoleIds.has(currentHoleId)
|
|
392
|
+
: true;
|
|
98
393
|
|
|
99
394
|
if (shouldStream) {
|
|
100
395
|
const children = current.props?.children;
|
|
101
|
-
const promise = (async () => {
|
|
396
|
+
const promise = runInRuntimeDynamicHole(() => (async () => {
|
|
102
397
|
try {
|
|
103
398
|
let html = "";
|
|
104
399
|
if (platformContext && platformContext.renderHtmlStream) {
|
|
@@ -109,33 +404,45 @@ function isClientComponent(type) {
|
|
|
109
404
|
html = await new Response(htmlStream).text();
|
|
110
405
|
}
|
|
111
406
|
|
|
112
|
-
const chunk = `\n<template id="ppr-content-${currentHoleId}">${html}</template>\n<script>(function(){var c=document.getElementById("ppr-content-${currentHoleId}");if(!c)return;var b=document.getElementById("B:${
|
|
407
|
+
const chunk = `\n<template id="ppr-content-${currentHoleId}">${html}</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`;
|
|
113
408
|
await writer.write(encoder.encode(chunk));
|
|
114
409
|
} catch (holeErr) {
|
|
115
410
|
console.error(`[Dinou PPR] Error resolving dynamic hole ${currentHoleId}:`, holeErr);
|
|
116
|
-
const
|
|
411
|
+
const rawErrMsg = isDevelopment
|
|
117
412
|
? (holeErr?.message || "Unknown dynamic error")
|
|
118
413
|
: "Error loading dynamic content";
|
|
119
|
-
const
|
|
414
|
+
const errMsg = escapeHtml(rawErrMsg);
|
|
415
|
+
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`;
|
|
120
416
|
await writer.write(encoder.encode(errChunk));
|
|
121
417
|
}
|
|
122
|
-
})();
|
|
418
|
+
})());
|
|
123
419
|
holePromises.push(promise);
|
|
420
|
+
return;
|
|
124
421
|
}
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
422
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
423
|
+
// Static <Suspense> boundary: do not re-stream it, but traverse its children & fallback
|
|
424
|
+
// in the same order as asyncRenderJSXToClientJSX so nested dynamic <Suspense> holes are
|
|
425
|
+
// discovered and holeIndex remains synchronized.
|
|
426
|
+
const runStaticScope =
|
|
427
|
+
staticParentHoles && staticParentHoles.has(currentHoleId)
|
|
428
|
+
? runInRuntimeDynamicHole
|
|
429
|
+
: runInRuntimeStaticSuspense;
|
|
430
|
+
await runStaticScope(async () => {
|
|
431
|
+
if (current.props?.children) {
|
|
432
|
+
await traverse(current.props.children);
|
|
433
|
+
}
|
|
434
|
+
if (current.props?.fallback) {
|
|
435
|
+
await traverse(current.props.fallback);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
133
438
|
return;
|
|
134
439
|
}
|
|
135
440
|
|
|
136
|
-
// Traverse
|
|
137
|
-
if (current
|
|
138
|
-
await
|
|
441
|
+
// Traverse host element / Fragment props or plain props object
|
|
442
|
+
if (current?.$$typeof === Symbol.for("react.transitional.element")) {
|
|
443
|
+
await traverseProps(current.props);
|
|
444
|
+
} else {
|
|
445
|
+
await traverseProps(current);
|
|
139
446
|
}
|
|
140
447
|
}
|
|
141
448
|
|
|
@@ -200,8 +507,23 @@ async function handlePprResume({
|
|
|
200
507
|
// 1. Immediately flush static shell prelude (0ms TTFB)
|
|
201
508
|
await writer.write(encoder.encode(shellPrelude));
|
|
202
509
|
|
|
510
|
+
let holes = Array.isArray(metadata?.holes) ? metadata.holes : null;
|
|
511
|
+
if ((!holes || holes.length === 0) && typeof shellPrelude === "string") {
|
|
512
|
+
const extracted = [
|
|
513
|
+
...shellPrelude.matchAll(/data-ppr-hole="(ppr-hole-\d+)"/g),
|
|
514
|
+
].map((m) => m[1]);
|
|
515
|
+
if (extracted.length > 0 || Array.isArray(metadata?.holes)) {
|
|
516
|
+
holes = extracted;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (Array.isArray(holes) && holes.length === 0) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
203
524
|
const dynamicState = { value: true };
|
|
204
525
|
const context = createRequestContext(simReq, bridge, platformContext, dynamicState);
|
|
526
|
+
context._isPprRuntimeResume = true;
|
|
205
527
|
if (typeof copyCustomContextProperties === "function") {
|
|
206
528
|
copyCustomContextProperties(rootContext, context);
|
|
207
529
|
}
|
|
@@ -216,17 +538,29 @@ async function handlePprResume({
|
|
|
216
538
|
queryObj,
|
|
217
539
|
isNotFound,
|
|
218
540
|
isDevelopment,
|
|
219
|
-
false
|
|
541
|
+
false,
|
|
542
|
+
{ skipLayoutProbe: true }
|
|
220
543
|
);
|
|
221
544
|
|
|
222
|
-
const
|
|
545
|
+
const staticParentHoles =
|
|
546
|
+
typeof shellPrelude === "string"
|
|
547
|
+
? new Set(
|
|
548
|
+
[
|
|
549
|
+
...shellPrelude.matchAll(
|
|
550
|
+
/data-ppr-static-parent="(ppr-hole-\d+)"/g
|
|
551
|
+
),
|
|
552
|
+
].map((m) => m[1])
|
|
553
|
+
)
|
|
554
|
+
: null;
|
|
555
|
+
|
|
223
556
|
await streamDynamicHoles(
|
|
224
557
|
jsx,
|
|
225
558
|
holes,
|
|
226
559
|
writer,
|
|
227
560
|
encoder,
|
|
228
561
|
platformContext,
|
|
229
|
-
isDevelopment
|
|
562
|
+
isDevelopment,
|
|
563
|
+
staticParentHoles
|
|
230
564
|
);
|
|
231
565
|
});
|
|
232
566
|
} catch (streamErr) {
|
|
@@ -260,8 +594,10 @@ async function handlePprResume({
|
|
|
260
594
|
export {
|
|
261
595
|
streamDynamicHoles,
|
|
262
596
|
handlePprResume,
|
|
597
|
+
spliceDynamicHolesIntoShell,
|
|
263
598
|
};
|
|
264
599
|
export default {
|
|
265
600
|
streamDynamicHoles,
|
|
266
601
|
handlePprResume,
|
|
602
|
+
spliceDynamicHolesIntoShell,
|
|
267
603
|
};
|