dinou 9.3.0 → 10.0.1
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 +196 -0
- package/README.md +157 -132
- package/dinou/adapters/bun.js +34 -5
- package/dinou/adapters/cloudflare.js +110 -17
- package/dinou/adapters/deno.js +46 -8
- package/dinou/adapters/netlify.js +86 -50
- package/dinou/adapters/node.js +8 -0
- package/dinou/assets.d.ts +32 -5
- package/dinou/bun/build.js +190 -106
- package/dinou/cli.js +992 -532
- package/dinou/cloudflare/build.js +187 -106
- package/dinou/compiled/autoprefixer/index.js +509 -517
- package/dinou/compiled/babel-core/index.js +738 -716
- package/dinou/compiled/babel-generator/index.js +341 -299
- package/dinou/compiled/babel-loader/index.js +766 -744
- package/dinou/compiled/babel-parser/index.js +2 -2
- package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
- package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
- package/dinou/compiled/babel-preset-react/index.js +752 -730
- package/dinou/compiled/babel-preset-typescript/index.js +738 -716
- package/dinou/compiled/babel-traverse/index.js +463 -433
- package/dinou/compiled/babel-types/index.js +176 -176
- package/dinou/compiled/chokidar/index.js +4 -4
- package/dinou/compiled/commander/index.js +15 -15
- package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
- package/dinou/compiled/css-loader/index.js +289 -289
- package/dinou/compiled/css-loader/runtime/api.js +85 -0
- package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
- package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
- package/dinou/compiled/css-loader/runtime/package.json +3 -0
- package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
- package/dinou/compiled/fast-glob/index.js +5810 -0
- package/dinou/compiled/generic-names/index.js +16 -16
- package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js → chunk-R6DP5ZYM.js} +36 -36
- package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
- package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
- package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
- package/dinou/compiled/postcss/index.js +83 -83
- package/dinou/compiled/postcss-import/index.js +147 -117
- package/dinou/compiled/postcss-modules/index.js +216 -216
- package/dinou/compiled/resolve/index.js +1224 -0
- package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
- package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
- package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
- package/dinou/compiled/rollup-plugin-json/index.js +22 -18
- package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
- package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
- package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
- package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
- package/dinou/compiled/vendors-manifest.json +59 -83
- package/dinou/core/asset-extensions.js +482 -33
- package/dinou/core/bailout-proxy.js +21 -2
- package/dinou/core/build-static-pages.js +523 -371
- package/dinou/core/builtin-asset-extensions.js +63 -0
- package/dinou/core/cache-revalidate.js +449 -256
- package/dinou/core/cache-slot.js +289 -79
- package/dinou/core/client-webpack.jsx +470 -39
- package/dinou/core/client.jsx +402 -39
- package/dinou/core/config.js +3 -0
- package/dinou/core/copy-static-dirs.js +98 -0
- package/dinou/core/createScopedName.js +22 -4
- package/dinou/core/dinou-paths.js +1 -1
- package/dinou/core/discover-layouts.js +200 -0
- package/dinou/core/edge-ssr.js +1 -1
- package/dinou/core/ensure-vendor-mode.js +78 -19
- package/dinou/core/env.js +544 -0
- package/dinou/core/export-static.js +41 -9
- package/dinou/core/generate-route-types.js +989 -95
- package/dinou/core/generate-static-rsc.js +5 -6
- package/dinou/core/generate-static.js +45 -6
- package/dinou/core/get-abs-path-with-ext.js +217 -75
- package/dinou/core/get-asset-from-manifest.js +19 -8
- package/dinou/core/get-error-jsx.js +4 -5
- package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
- package/dinou/core/get-jsx.js +220 -53
- package/dinou/core/handler.js +1647 -466
- package/dinou/core/import-module.js +7 -0
- package/dinou/core/layout-functions.js +72 -13
- package/dinou/core/link.jsx +34 -6
- package/dinou/core/load-dinou-config.js +520 -89
- package/dinou/core/manifest-provider.js +4 -14
- package/dinou/core/navigation-utils.js +141 -3
- package/dinou/core/navigation.js +134 -50
- package/dinou/core/node-middleware-runner.js +165 -0
- package/dinou/core/postcss-pipeline.js +236 -0
- package/dinou/core/ppr-context.js +114 -22
- package/dinou/core/ppr-runtime.js +391 -127
- package/dinou/core/redirect.jsx +1 -1
- package/dinou/core/render-jsx-to-client-jsx.js +216 -48
- package/dinou/core/request-context.js +59 -3
- package/dinou/core/resolve-contextual-dinou.js +523 -0
- package/dinou/core/resolve-setup-files.js +85 -27
- package/dinou/core/revalidating.js +10 -2
- package/dinou/core/route-generator.js +6 -2
- package/dinou/core/rsc-renderer.js +4 -1
- package/dinou/core/run-ssg.js +6 -0
- package/dinou/core/runtime-env.js +265 -0
- package/dinou/core/server-css-modules-plugin.js +155 -0
- package/dinou/core/server-function-proxy-webpack.js +27 -2
- package/dinou/core/server-function-proxy.js +27 -2
- package/dinou/core/slot.js +47 -2
- package/dinou/core/static-assets.js +503 -0
- package/dinou/core/storage-adapter.js +452 -24
- package/dinou/core/transform-server-functions.js +272 -24
- package/dinou/core/tsconfig-aliases.js +964 -0
- package/dinou/core/uneject.js +640 -0
- package/dinou/core/url-resolver.js +1 -1
- package/dinou/core/vfs.js +11 -2
- package/dinou/css.d.ts +4 -1
- package/dinou/deno/build.js +205 -153
- package/dinou/deno/seed-kv.js +4 -0
- package/dinou/env.d.ts +22 -2
- package/dinou/esbuild/build.js +40 -50
- package/dinou/esbuild/dev.js +33 -7
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
- package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
- package/dinou/esbuild/helpers-esbuild/write.js +13 -3
- package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
- package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
- package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
- package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
- package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
- package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
- package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
- package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
- package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
- package/dinou/index.d.ts +1028 -88
- package/dinou/node/build.js +138 -74
- package/dinou/node/bundle-dual-engine.js +393 -131
- package/dinou/node/dev.js +1005 -275
- package/dinou/package.json +11 -34
- package/dinou/rollup/postcss.config.js +3 -4
- package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
- package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
- package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
- package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
- package/dinou/rollup/rollup.config.js +174 -101
- package/dinou/scripts/build-vendors.js +123 -33
- package/dinou/server.d.ts +126 -15
- package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
- package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
- package/dinou/webpack/loaders/server-functions-loader.js +1 -1
- package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
- package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
- package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
- package/dinou/webpack/postcss.config.js +3 -4
- package/dinou/webpack/webpack.config.js +408 -132
- package/eject.js +6 -224
- package/package.json +7 -9
- package/dinou/compiled/cross-env/index.js +0 -661
- package/dinou/compiled/dotenv/index.js +0 -375
- package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
- package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
- package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
- package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
- package/dinou/compiled/tsconfig-paths-webpack-plugin/index.js +0 -3956
|
@@ -4,11 +4,16 @@
|
|
|
4
4
|
// streams dynamic Suspense holes as they resolve over the same HTTP connection.
|
|
5
5
|
// Designed for the Dual-Bundle architecture (Pass A: RSC, Pass B: SSR).
|
|
6
6
|
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
9
|
import React from "react";
|
|
8
10
|
import { renderRSCStream } from "./rsc-renderer.js";
|
|
9
11
|
import { getClientManifest } from "./manifest-provider.js";
|
|
10
12
|
import { requestStorage, setCurrentContext } from "./request-context.js";
|
|
11
13
|
import getJSX from "./get-jsx.js";
|
|
14
|
+
import { getStorageAdapter, readDist2Fallback } from "./storage-adapter.js";
|
|
15
|
+
import { deserializeJSX } from "./cache-slot.js";
|
|
16
|
+
import { getActiveLayoutChain } from "./layout-functions.js";
|
|
12
17
|
import {
|
|
13
18
|
asyncRenderJSXToClientJSX,
|
|
14
19
|
invokeWithServerHooksDispatcher,
|
|
@@ -18,6 +23,145 @@ import {
|
|
|
18
23
|
runInRuntimeStaticSuspense,
|
|
19
24
|
runInRuntimeDynamicHole,
|
|
20
25
|
} from "./ppr-context.js";
|
|
26
|
+
import { fetchCloudflareDist2Asset } from "./static-assets.js";
|
|
27
|
+
|
|
28
|
+
function safeJsonForInlineScript(str) {
|
|
29
|
+
return JSON.stringify(str)
|
|
30
|
+
.replace(/</g, "\\u003c")
|
|
31
|
+
.replace(/>/g, "\\u003e")
|
|
32
|
+
.replace(/\u2028/g, "\\u2028")
|
|
33
|
+
.replace(/\u2029/g, "\\u2029");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function formatRscPushScript(kind, chunkStr) {
|
|
37
|
+
const arrName = `__DINOU_RSC_${kind}__`;
|
|
38
|
+
const pushFn = `__DINOU_RSC_${kind}_PUSH__`;
|
|
39
|
+
const encoded = safeJsonForInlineScript(chunkStr);
|
|
40
|
+
return `<script>(self.${arrName}=self.${arrName}||[]).push(${encoded});if(self.${pushFn})self.${pushFn}(${encoded});</script>`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function formatRscDoneScript(kind) {
|
|
44
|
+
const doneName = `__DINOU_RSC_${kind}_DONE__`;
|
|
45
|
+
const closeFn = `__DINOU_RSC_${kind}_CLOSE__`;
|
|
46
|
+
return `<script>self.${doneName}=true;if(self.${closeFn})self.${closeFn}();</script>`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function readShellJsonFromStorage(storage, key, platformContext, reqUrl) {
|
|
50
|
+
if (!key) return null;
|
|
51
|
+
if (storage) {
|
|
52
|
+
try {
|
|
53
|
+
const item = await storage.get(key);
|
|
54
|
+
if (item && typeof item.content === "string" && item.content.trim().startsWith("{")) {
|
|
55
|
+
return item.content;
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {}
|
|
58
|
+
}
|
|
59
|
+
const isDeleted =
|
|
60
|
+
storage &&
|
|
61
|
+
(typeof storage.isKeyDeleted === "function"
|
|
62
|
+
? await storage.isKeyDeleted(key)
|
|
63
|
+
: typeof storage.isDeleted === "function" && storage.isDeleted(key));
|
|
64
|
+
if (isDeleted) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (platformContext?.env?.ASSETS && reqUrl) {
|
|
68
|
+
try {
|
|
69
|
+
const assetRes = await fetchCloudflareDist2Asset(
|
|
70
|
+
platformContext.env.ASSETS,
|
|
71
|
+
key,
|
|
72
|
+
reqUrl
|
|
73
|
+
);
|
|
74
|
+
if (assetRes && assetRes.status === 200) {
|
|
75
|
+
const txt = await assetRes.text();
|
|
76
|
+
if (txt && txt.trim().startsWith("{")) {
|
|
77
|
+
if (storage) {
|
|
78
|
+
try {
|
|
79
|
+
await storage.set(key, txt);
|
|
80
|
+
} catch (e) {}
|
|
81
|
+
}
|
|
82
|
+
return txt;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {}
|
|
86
|
+
}
|
|
87
|
+
if (storage) {
|
|
88
|
+
const dist2Item = await readDist2Fallback(storage, key);
|
|
89
|
+
if (
|
|
90
|
+
dist2Item &&
|
|
91
|
+
typeof dist2Item.content === "string" &&
|
|
92
|
+
dist2Item.content.trim().startsWith("{")
|
|
93
|
+
) {
|
|
94
|
+
return dist2Item.content;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
try {
|
|
98
|
+
const diskPath = path.resolve(process.cwd(), ".dinou/dist2", key);
|
|
99
|
+
if (existsSync(diskPath)) {
|
|
100
|
+
const txt = readFileSync(diskPath, "utf8");
|
|
101
|
+
if (txt && txt.trim().startsWith("{")) {
|
|
102
|
+
return txt;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function replaceHolesWithMap(node, liveHolesMap) {
|
|
111
|
+
if (
|
|
112
|
+
!node ||
|
|
113
|
+
typeof node !== "object" ||
|
|
114
|
+
node instanceof Promise ||
|
|
115
|
+
node.$$typeof === Symbol.for("react.client.reference") ||
|
|
116
|
+
typeof node.then === "function"
|
|
117
|
+
) {
|
|
118
|
+
return node;
|
|
119
|
+
}
|
|
120
|
+
if (Array.isArray(node)) {
|
|
121
|
+
return node.map((item) => replaceHolesWithMap(item, liveHolesMap));
|
|
122
|
+
}
|
|
123
|
+
if (node.$$typeof === Symbol.for("react.transitional.element")) {
|
|
124
|
+
const holeId = node.props && node.props["data-ppr-hole"];
|
|
125
|
+
if (typeof holeId === "string" && liveHolesMap.has(holeId)) {
|
|
126
|
+
return liveHolesMap.get(holeId);
|
|
127
|
+
}
|
|
128
|
+
if (node.props && typeof node.props === "object") {
|
|
129
|
+
let changed = false;
|
|
130
|
+
const newProps = { ...node.props };
|
|
131
|
+
for (const [k, v] of Object.entries(node.props)) {
|
|
132
|
+
if (v && typeof v === "object") {
|
|
133
|
+
const updated = replaceHolesWithMap(v, liveHolesMap);
|
|
134
|
+
if (updated !== v) {
|
|
135
|
+
newProps[k] = updated;
|
|
136
|
+
changed = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (changed) {
|
|
141
|
+
if (node.key != null) newProps.key = node.key;
|
|
142
|
+
const children = newProps.children;
|
|
143
|
+
if (Array.isArray(children)) {
|
|
144
|
+
delete newProps.children;
|
|
145
|
+
return React.createElement(node.type, newProps, ...children);
|
|
146
|
+
}
|
|
147
|
+
return React.createElement(node.type, newProps);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return node;
|
|
151
|
+
}
|
|
152
|
+
let changed = false;
|
|
153
|
+
const clone = { ...node };
|
|
154
|
+
for (const [k, v] of Object.entries(node)) {
|
|
155
|
+
if (v && typeof v === "object") {
|
|
156
|
+
const updated = replaceHolesWithMap(v, liveHolesMap);
|
|
157
|
+
if (updated !== v) {
|
|
158
|
+
clone[k] = updated;
|
|
159
|
+
changed = true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return changed ? clone : node;
|
|
164
|
+
}
|
|
21
165
|
|
|
22
166
|
async function PprDynamicHoleBoundary({ holeId, children }) {
|
|
23
167
|
return await runInRuntimeDynamicHole(
|
|
@@ -58,7 +202,7 @@ async function spliceDynamicHolesIntoShell(
|
|
|
58
202
|
const knownHoleIds = new Set();
|
|
59
203
|
const staticParentHoleIds = new Set();
|
|
60
204
|
function collectKnownHoles(node) {
|
|
61
|
-
if (!node || typeof node !== "object") return;
|
|
205
|
+
if (!node || typeof node !== "object" || node instanceof Promise || node.$$typeof === Symbol.for("react.client.reference") || typeof node.then === "function") return;
|
|
62
206
|
if (Array.isArray(node)) {
|
|
63
207
|
for (const item of node) collectKnownHoles(item);
|
|
64
208
|
return;
|
|
@@ -95,32 +239,52 @@ async function spliceDynamicHolesIntoShell(
|
|
|
95
239
|
let holeIndex = Number(startHoleIndex) || 0;
|
|
96
240
|
const liveHolesMap = new Map();
|
|
97
241
|
|
|
98
|
-
async function traverseProps(props) {
|
|
242
|
+
async function traverseProps(props, inClientProps = false) {
|
|
99
243
|
if (!props || typeof props !== "object") return;
|
|
100
244
|
for (const [, value] of Object.entries(props)) {
|
|
101
|
-
if (
|
|
102
|
-
|
|
245
|
+
if (liveHolesMap.size >= knownHoleIds.size) return;
|
|
246
|
+
if (value && (typeof value === "object" || typeof value === "function")) {
|
|
247
|
+
await traverse(value, inClientProps);
|
|
103
248
|
}
|
|
104
249
|
}
|
|
105
250
|
}
|
|
106
251
|
|
|
107
|
-
async function traverse(current) {
|
|
252
|
+
async function traverse(current, inClientProps = false) {
|
|
108
253
|
if (!current || liveHolesMap.size >= knownHoleIds.size) return;
|
|
109
254
|
if (Array.isArray(current)) {
|
|
110
255
|
for (const item of current) {
|
|
111
256
|
if (liveHolesMap.size >= knownHoleIds.size) return;
|
|
112
|
-
await traverse(item);
|
|
257
|
+
await traverse(item, inClientProps);
|
|
113
258
|
}
|
|
114
259
|
return;
|
|
115
260
|
}
|
|
116
|
-
if (typeof current !== "object" || current instanceof Promise) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
261
|
if (
|
|
120
262
|
isClientComponentRef(current?.type) ||
|
|
121
263
|
current?.$$typeof === Symbol.for("react.client.reference")
|
|
122
264
|
) {
|
|
123
|
-
await traverseProps(current?.props);
|
|
265
|
+
await traverseProps(current?.props, true);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (
|
|
269
|
+
current instanceof Promise ||
|
|
270
|
+
((typeof current === "object" || typeof current === "function") &&
|
|
271
|
+
typeof current?.then === "function")
|
|
272
|
+
) {
|
|
273
|
+
if (inClientProps) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
const resolved = await current;
|
|
278
|
+
await traverse(resolved, false);
|
|
279
|
+
} catch (err) {
|
|
280
|
+
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
console.error("[Dinou PPR] Error awaiting JSX promise in hole splice:", err);
|
|
284
|
+
}
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (typeof current !== "object") {
|
|
124
288
|
return;
|
|
125
289
|
}
|
|
126
290
|
if (typeof current?.type === "function") {
|
|
@@ -128,7 +292,7 @@ async function spliceDynamicHolesIntoShell(
|
|
|
128
292
|
const evaluated = await invokeWithServerHooksDispatcher(() =>
|
|
129
293
|
current.type(current.props || {})
|
|
130
294
|
);
|
|
131
|
-
await traverse(evaluated);
|
|
295
|
+
await traverse(evaluated, false);
|
|
132
296
|
} catch (err) {
|
|
133
297
|
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
134
298
|
return;
|
|
@@ -143,14 +307,14 @@ async function spliceDynamicHolesIntoShell(
|
|
|
143
307
|
current.type.$$typeof === Symbol.for("react.forward_ref")
|
|
144
308
|
) {
|
|
145
309
|
if (isClientComponentRef(current.type)) {
|
|
146
|
-
await traverseProps(current.props);
|
|
310
|
+
await traverseProps(current.props, true);
|
|
147
311
|
return;
|
|
148
312
|
}
|
|
149
313
|
try {
|
|
150
314
|
const rendered = await invokeWithServerHooksDispatcher(() =>
|
|
151
315
|
current.type.render(current.props || {}, current.ref)
|
|
152
316
|
);
|
|
153
|
-
await traverse(rendered);
|
|
317
|
+
await traverse(rendered, false);
|
|
154
318
|
} catch (err) {
|
|
155
319
|
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
156
320
|
return;
|
|
@@ -165,7 +329,7 @@ async function spliceDynamicHolesIntoShell(
|
|
|
165
329
|
current.type.$$typeof === Symbol.for("react.memo")
|
|
166
330
|
) {
|
|
167
331
|
if (isClientComponentRef(current.type)) {
|
|
168
|
-
await traverseProps(current.props);
|
|
332
|
+
await traverseProps(current.props, true);
|
|
169
333
|
return;
|
|
170
334
|
}
|
|
171
335
|
try {
|
|
@@ -185,7 +349,7 @@ async function spliceDynamicHolesIntoShell(
|
|
|
185
349
|
innerComp.render(current.props || {}, current.ref)
|
|
186
350
|
);
|
|
187
351
|
}
|
|
188
|
-
await traverse(rendered);
|
|
352
|
+
await traverse(rendered, false);
|
|
189
353
|
} catch (err) {
|
|
190
354
|
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
191
355
|
return;
|
|
@@ -220,72 +384,24 @@ async function spliceDynamicHolesIntoShell(
|
|
|
220
384
|
: runInRuntimeStaticSuspense;
|
|
221
385
|
await runStaticScope(async () => {
|
|
222
386
|
if (current.props?.children) {
|
|
223
|
-
await traverse(current.props.children);
|
|
387
|
+
await traverse(current.props.children, false);
|
|
224
388
|
}
|
|
225
389
|
if (current.props?.fallback) {
|
|
226
|
-
await traverse(current.props.fallback);
|
|
390
|
+
await traverse(current.props.fallback, false);
|
|
227
391
|
}
|
|
228
392
|
});
|
|
229
393
|
return;
|
|
230
394
|
}
|
|
231
395
|
if (current?.$$typeof === Symbol.for("react.transitional.element")) {
|
|
232
|
-
await traverseProps(current.props);
|
|
396
|
+
await traverseProps(current.props, false);
|
|
233
397
|
} else {
|
|
234
|
-
await traverseProps(current);
|
|
398
|
+
await traverseProps(current, inClientProps);
|
|
235
399
|
}
|
|
236
400
|
}
|
|
237
401
|
|
|
238
402
|
await traverse(livePageNode);
|
|
239
403
|
|
|
240
|
-
|
|
241
|
-
if (!node || typeof node !== "object") return node;
|
|
242
|
-
if (Array.isArray(node)) {
|
|
243
|
-
return node.map((item) => replaceHoles(item));
|
|
244
|
-
}
|
|
245
|
-
if (node.$$typeof === Symbol.for("react.transitional.element")) {
|
|
246
|
-
const holeId = node.props && node.props["data-ppr-hole"];
|
|
247
|
-
if (typeof holeId === "string" && liveHolesMap.has(holeId)) {
|
|
248
|
-
return liveHolesMap.get(holeId);
|
|
249
|
-
}
|
|
250
|
-
if (node.props && typeof node.props === "object") {
|
|
251
|
-
let changed = false;
|
|
252
|
-
const newProps = { ...node.props };
|
|
253
|
-
for (const [k, v] of Object.entries(node.props)) {
|
|
254
|
-
if (v && typeof v === "object") {
|
|
255
|
-
const updated = replaceHoles(v);
|
|
256
|
-
if (updated !== v) {
|
|
257
|
-
newProps[k] = updated;
|
|
258
|
-
changed = true;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (changed) {
|
|
263
|
-
if (node.key != null) newProps.key = node.key;
|
|
264
|
-
const children = newProps.children;
|
|
265
|
-
if (Array.isArray(children)) {
|
|
266
|
-
delete newProps.children;
|
|
267
|
-
return React.createElement(node.type, newProps, ...children);
|
|
268
|
-
}
|
|
269
|
-
return React.createElement(node.type, newProps);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return node;
|
|
273
|
-
}
|
|
274
|
-
let changed = false;
|
|
275
|
-
const clone = { ...node };
|
|
276
|
-
for (const [k, v] of Object.entries(node)) {
|
|
277
|
-
if (v && typeof v === "object") {
|
|
278
|
-
const updated = replaceHoles(v);
|
|
279
|
-
if (updated !== v) {
|
|
280
|
-
clone[k] = updated;
|
|
281
|
-
changed = true;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return changed ? clone : node;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
return replaceHoles(cachedShellTree);
|
|
404
|
+
return replaceHolesWithMap(cachedShellTree, liveHolesMap);
|
|
289
405
|
}
|
|
290
406
|
|
|
291
407
|
/**
|
|
@@ -306,7 +422,8 @@ async function streamDynamicHoles(
|
|
|
306
422
|
encoder,
|
|
307
423
|
platformContext,
|
|
308
424
|
isDevelopment = false,
|
|
309
|
-
staticParentHoles = null
|
|
425
|
+
staticParentHoles = null,
|
|
426
|
+
resolvedHolesOut = null
|
|
310
427
|
) {
|
|
311
428
|
let holeIndex = 0;
|
|
312
429
|
const holePromises = [];
|
|
@@ -321,38 +438,58 @@ async function streamDynamicHoles(
|
|
|
321
438
|
|
|
322
439
|
const clientManifest = getClientManifest();
|
|
323
440
|
|
|
324
|
-
async function traverseProps(props) {
|
|
441
|
+
async function traverseProps(props, inClientProps = false) {
|
|
325
442
|
if (!props || typeof props !== "object") return;
|
|
326
443
|
for (const [, value] of Object.entries(props)) {
|
|
327
444
|
if (hasExplicitHoles && holePromises.length >= knownHoleIds.size) return;
|
|
328
|
-
if (value && typeof value === "object") {
|
|
329
|
-
await traverse(value);
|
|
445
|
+
if (value && (typeof value === "object" || typeof value === "function")) {
|
|
446
|
+
await traverse(value, inClientProps);
|
|
330
447
|
}
|
|
331
448
|
}
|
|
332
449
|
}
|
|
333
450
|
|
|
334
|
-
async function traverse(current) {
|
|
451
|
+
async function traverse(current, inClientProps = false) {
|
|
335
452
|
if (!current || (hasExplicitHoles && holePromises.length >= knownHoleIds.size)) return;
|
|
336
453
|
|
|
337
454
|
// Handle Arrays (children)
|
|
338
455
|
if (Array.isArray(current)) {
|
|
339
456
|
for (const item of current) {
|
|
340
457
|
if (hasExplicitHoles && holePromises.length >= knownHoleIds.size) return;
|
|
341
|
-
await traverse(item);
|
|
458
|
+
await traverse(item, inClientProps);
|
|
342
459
|
}
|
|
343
460
|
return;
|
|
344
461
|
}
|
|
345
462
|
|
|
346
|
-
if (typeof current !== "object" || current instanceof Promise) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
463
|
// Handle Client Component: do NOT execute, only traverse props in deterministic order
|
|
351
464
|
if (
|
|
352
465
|
isClientComponentRef(current?.type) ||
|
|
353
466
|
current?.$$typeof === Symbol.for("react.client.reference")
|
|
354
467
|
) {
|
|
355
|
-
await traverseProps(current?.props);
|
|
468
|
+
await traverseProps(current?.props, true);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (
|
|
473
|
+
current instanceof Promise ||
|
|
474
|
+
((typeof current === "object" || typeof current === "function") &&
|
|
475
|
+
typeof current?.then === "function")
|
|
476
|
+
) {
|
|
477
|
+
if (inClientProps) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
const resolved = await current;
|
|
482
|
+
await traverse(resolved, false);
|
|
483
|
+
} catch (err) {
|
|
484
|
+
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
console.error("[Dinou PPR] Error awaiting JSX promise in hole traversal:", err);
|
|
488
|
+
}
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (typeof current !== "object") {
|
|
356
493
|
return;
|
|
357
494
|
}
|
|
358
495
|
|
|
@@ -362,7 +499,7 @@ async function streamDynamicHoles(
|
|
|
362
499
|
const evaluated = await invokeWithServerHooksDispatcher(() =>
|
|
363
500
|
current.type(current.props || {})
|
|
364
501
|
);
|
|
365
|
-
await traverse(evaluated);
|
|
502
|
+
await traverse(evaluated, false);
|
|
366
503
|
} catch (err) {
|
|
367
504
|
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
368
505
|
return;
|
|
@@ -379,14 +516,14 @@ async function streamDynamicHoles(
|
|
|
379
516
|
current.type.$$typeof === Symbol.for("react.forward_ref")
|
|
380
517
|
) {
|
|
381
518
|
if (isClientComponentRef(current.type)) {
|
|
382
|
-
await traverseProps(current.props);
|
|
519
|
+
await traverseProps(current.props, true);
|
|
383
520
|
return;
|
|
384
521
|
}
|
|
385
522
|
try {
|
|
386
523
|
const rendered = await invokeWithServerHooksDispatcher(() =>
|
|
387
524
|
current.type.render(current.props || {}, current.ref)
|
|
388
525
|
);
|
|
389
|
-
await traverse(rendered);
|
|
526
|
+
await traverse(rendered, false);
|
|
390
527
|
} catch (err) {
|
|
391
528
|
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
392
529
|
return;
|
|
@@ -403,7 +540,7 @@ async function streamDynamicHoles(
|
|
|
403
540
|
current.type.$$typeof === Symbol.for("react.memo")
|
|
404
541
|
) {
|
|
405
542
|
if (isClientComponentRef(current.type)) {
|
|
406
|
-
await traverseProps(current.props);
|
|
543
|
+
await traverseProps(current.props, true);
|
|
407
544
|
return;
|
|
408
545
|
}
|
|
409
546
|
try {
|
|
@@ -423,7 +560,7 @@ async function streamDynamicHoles(
|
|
|
423
560
|
innerComp.render(current.props || {}, current.ref)
|
|
424
561
|
);
|
|
425
562
|
}
|
|
426
|
-
await traverse(rendered);
|
|
563
|
+
await traverse(rendered, false);
|
|
427
564
|
} catch (err) {
|
|
428
565
|
if (err && err.$$typeof === SKIP_STATIC_SUSPENSE_SYMBOL) {
|
|
429
566
|
return;
|
|
@@ -449,21 +586,37 @@ async function streamDynamicHoles(
|
|
|
449
586
|
|
|
450
587
|
if (shouldStream) {
|
|
451
588
|
const children = current.props?.children;
|
|
589
|
+
const suspenseProps = current.props || {};
|
|
590
|
+
const suspenseKey = current.key;
|
|
452
591
|
const promise = runInRuntimeDynamicHole(() => (async () => {
|
|
453
592
|
try {
|
|
454
593
|
let html = "";
|
|
594
|
+
const resolvedChildren = await asyncRenderJSXToClientJSX(children);
|
|
595
|
+
if (resolvedHolesOut && typeof resolvedHolesOut.set === "function") {
|
|
596
|
+
resolvedHolesOut.set(
|
|
597
|
+
currentHoleId,
|
|
598
|
+
React.createElement(
|
|
599
|
+
React.Suspense,
|
|
600
|
+
{
|
|
601
|
+
...suspenseProps,
|
|
602
|
+
...(suspenseKey != null ? { key: suspenseKey } : {}),
|
|
603
|
+
children: resolvedChildren,
|
|
604
|
+
}
|
|
605
|
+
)
|
|
606
|
+
);
|
|
607
|
+
}
|
|
455
608
|
if (platformContext && platformContext.renderHtmlStream) {
|
|
456
|
-
const resolvedChildren = await asyncRenderJSXToClientJSX(children);
|
|
457
609
|
const rscStream = renderRSCStream(resolvedChildren, clientManifest, { runtime: "edge" });
|
|
458
610
|
const htmlStream = await platformContext.renderHtmlStream(rscStream, {
|
|
459
|
-
bootstrapModules: [],
|
|
611
|
+
bootstrapModules: [], importMapHtml: "",
|
|
460
612
|
});
|
|
461
613
|
html = await new Response(htmlStream).text();
|
|
462
614
|
}
|
|
463
615
|
|
|
464
|
-
const chunk = `\n<template id="ppr-content-${currentHoleId}"
|
|
616
|
+
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`;
|
|
465
617
|
await writer.write(encoder.encode(chunk));
|
|
466
618
|
} catch (holeErr) {
|
|
619
|
+
if (resolvedHolesOut) resolvedHolesOut._hadError = true;
|
|
467
620
|
console.error(`[Dinou PPR] Error resolving dynamic hole ${currentHoleId}:`, holeErr);
|
|
468
621
|
const rawErrMsg = isDevelopment
|
|
469
622
|
? (holeErr?.message || "Unknown dynamic error")
|
|
@@ -486,10 +639,10 @@ async function streamDynamicHoles(
|
|
|
486
639
|
: runInRuntimeStaticSuspense;
|
|
487
640
|
await runStaticScope(async () => {
|
|
488
641
|
if (current.props?.children) {
|
|
489
|
-
await traverse(current.props.children);
|
|
642
|
+
await traverse(current.props.children, false);
|
|
490
643
|
}
|
|
491
644
|
if (current.props?.fallback) {
|
|
492
|
-
await traverse(current.props.fallback);
|
|
645
|
+
await traverse(current.props.fallback, false);
|
|
493
646
|
}
|
|
494
647
|
});
|
|
495
648
|
return;
|
|
@@ -497,9 +650,9 @@ async function streamDynamicHoles(
|
|
|
497
650
|
|
|
498
651
|
// Traverse host element / Fragment props or plain props object
|
|
499
652
|
if (current?.$$typeof === Symbol.for("react.transitional.element")) {
|
|
500
|
-
await traverseProps(current.props);
|
|
653
|
+
await traverseProps(current.props, false);
|
|
501
654
|
} else {
|
|
502
|
-
await traverseProps(current);
|
|
655
|
+
await traverseProps(current, inClientProps);
|
|
503
656
|
}
|
|
504
657
|
}
|
|
505
658
|
|
|
@@ -544,11 +697,28 @@ async function handlePprResume({
|
|
|
544
697
|
`<script>window.__DINOU_USE_STATIC__ = false; window.__DINOU_PPR__ = true;</script></head>`
|
|
545
698
|
);
|
|
546
699
|
}
|
|
700
|
+
if (!shellHtml.includes("window.__DINOU_PPR_RESUME__")) {
|
|
701
|
+
if (/window\.__DINOU_PPR__\s*=\s*true;?/.test(shellHtml)) {
|
|
702
|
+
shellHtml = shellHtml.replace(
|
|
703
|
+
/window\.__DINOU_PPR__\s*=\s*true;?/,
|
|
704
|
+
"window.__DINOU_PPR__ = true; window.__DINOU_PPR_RESUME__ = true;"
|
|
705
|
+
);
|
|
706
|
+
} else if (shellHtml.includes("</head>")) {
|
|
707
|
+
shellHtml = shellHtml.replace(
|
|
708
|
+
"</head>",
|
|
709
|
+
`<script>window.__DINOU_PPR_RESUME__ = true;</script></head>`
|
|
710
|
+
);
|
|
711
|
+
} else {
|
|
712
|
+
shellHtml = `<script>window.__DINOU_PPR_RESUME__ = true;</script>${shellHtml}`;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
547
715
|
}
|
|
548
716
|
|
|
549
717
|
// Separate shell into prelude (up to </body>) and postlude
|
|
550
718
|
const lowerHtml = shellHtml.toLowerCase();
|
|
551
|
-
const
|
|
719
|
+
const mainScriptMatch = typeof shellHtml === "string" ? shellHtml.match(/<script\b[^>]*\bsrc="\/(?:runtime|main)[^"]*"[^>]*><\/script>/i) : null;
|
|
720
|
+
const rawBodyCloseIndex = lowerHtml.lastIndexOf("</body>");
|
|
721
|
+
const bodyCloseIndex = mainScriptMatch && typeof mainScriptMatch.index === "number" && (rawBodyCloseIndex === -1 || mainScriptMatch.index < rawBodyCloseIndex) ? mainScriptMatch.index : rawBodyCloseIndex;
|
|
552
722
|
let shellPrelude =
|
|
553
723
|
bodyCloseIndex !== -1 ? shellHtml.slice(0, bodyCloseIndex) : shellHtml;
|
|
554
724
|
let shellPostlude =
|
|
@@ -564,6 +734,32 @@ async function handlePprResume({
|
|
|
564
734
|
// 1. Immediately flush static shell prelude (0ms TTFB)
|
|
565
735
|
await writer.write(encoder.encode(shellPrelude));
|
|
566
736
|
|
|
737
|
+
const storage = getStorageAdapter();
|
|
738
|
+
const cleanRel = (reqPath || "").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
739
|
+
const reqSegments = cleanRel ? cleanRel.split("/").filter(Boolean) : [];
|
|
740
|
+
const srcFolder = path.resolve(process.cwd(), "src");
|
|
741
|
+
let activeChain = [];
|
|
742
|
+
try {
|
|
743
|
+
activeChain = getActiveLayoutChain(reqSegments, queryObj || {}, srcFolder);
|
|
744
|
+
} catch (e) {}
|
|
745
|
+
const hasActiveLayout = activeChain.length > 0;
|
|
746
|
+
const leafLayoutKey = hasActiveLayout ? activeChain[0].cleanLayoutKey : null;
|
|
747
|
+
const shellPageKey = cleanRel ? `${cleanRel}/shell.page.json` : "shell.page.json";
|
|
748
|
+
const shellLayoutKey = hasActiveLayout
|
|
749
|
+
? leafLayoutKey
|
|
750
|
+
? `${leafLayoutKey}/shell.layout.json`
|
|
751
|
+
: "shell.layout.json"
|
|
752
|
+
: null;
|
|
753
|
+
const reqOriginUrl = simReq?.url
|
|
754
|
+
? `http://${simReq.headers?.host || "localhost:3000"}${simReq.url}`
|
|
755
|
+
: null;
|
|
756
|
+
const [pageShellJson, layoutShellJson] = await Promise.all([
|
|
757
|
+
readShellJsonFromStorage(storage, shellPageKey, platformContext, reqOriginUrl),
|
|
758
|
+
hasActiveLayout
|
|
759
|
+
? readShellJsonFromStorage(storage, shellLayoutKey, platformContext, reqOriginUrl)
|
|
760
|
+
: Promise.resolve(null),
|
|
761
|
+
]);
|
|
762
|
+
|
|
567
763
|
let holes = Array.isArray(metadata?.holes) ? metadata.holes : null;
|
|
568
764
|
if ((!holes || holes.length === 0) && typeof shellPrelude === "string") {
|
|
569
765
|
const extracted = [
|
|
@@ -574,10 +770,6 @@ async function handlePprResume({
|
|
|
574
770
|
}
|
|
575
771
|
}
|
|
576
772
|
|
|
577
|
-
if (Array.isArray(holes) && holes.length === 0) {
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
773
|
const dynamicState = { value: true };
|
|
582
774
|
const context = createRequestContext(simReq, bridge, platformContext, dynamicState);
|
|
583
775
|
context._isPprRuntimeResume = true;
|
|
@@ -588,37 +780,90 @@ async function handlePprResume({
|
|
|
588
780
|
setCurrentContext(context);
|
|
589
781
|
}
|
|
590
782
|
|
|
783
|
+
const resolvedHolesMap = new Map();
|
|
784
|
+
|
|
591
785
|
await requestStorage.run(context, async () => {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
786
|
+
if (!Array.isArray(holes) || holes.length > 0) {
|
|
787
|
+
const isNotFound = { value: false };
|
|
788
|
+
const jsx = await getJSX(
|
|
789
|
+
reqPath,
|
|
790
|
+
queryObj,
|
|
791
|
+
isNotFound,
|
|
792
|
+
isDevelopment,
|
|
793
|
+
false,
|
|
794
|
+
{ skipLayoutProbe: true }
|
|
795
|
+
);
|
|
601
796
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
797
|
+
const staticParentHoles =
|
|
798
|
+
typeof shellPrelude === "string"
|
|
799
|
+
? new Set(
|
|
800
|
+
[
|
|
801
|
+
...shellPrelude.matchAll(
|
|
802
|
+
/data-ppr-static-parent="(ppr-hole-\d+)"/g
|
|
803
|
+
),
|
|
804
|
+
].map((m) => m[1])
|
|
805
|
+
)
|
|
806
|
+
: null;
|
|
807
|
+
|
|
808
|
+
await streamDynamicHoles(
|
|
809
|
+
jsx,
|
|
810
|
+
holes,
|
|
811
|
+
writer,
|
|
812
|
+
encoder,
|
|
813
|
+
platformContext,
|
|
814
|
+
isDevelopment,
|
|
815
|
+
staticParentHoles,
|
|
816
|
+
resolvedHolesMap
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
if (
|
|
821
|
+
!resolvedHolesMap._hadError &&
|
|
822
|
+
pageShellJson &&
|
|
823
|
+
(!hasActiveLayout || layoutShellJson)
|
|
824
|
+
) {
|
|
825
|
+
try {
|
|
826
|
+
const clientManifest = getClientManifest();
|
|
827
|
+
const cachedPageTree = deserializeJSX(pageShellJson);
|
|
828
|
+
const splicedPageTree = replaceHolesWithMap(cachedPageTree, resolvedHolesMap);
|
|
829
|
+
const pageRscStream = renderRSCStream(splicedPageTree, clientManifest, {
|
|
830
|
+
runtime: "edge",
|
|
831
|
+
});
|
|
832
|
+
let layoutRscPromise = Promise.resolve("");
|
|
833
|
+
if (hasActiveLayout && layoutShellJson) {
|
|
834
|
+
const cachedLayoutTree = deserializeJSX(layoutShellJson);
|
|
835
|
+
const splicedLayoutTree = replaceHolesWithMap(
|
|
836
|
+
cachedLayoutTree,
|
|
837
|
+
resolvedHolesMap
|
|
838
|
+
);
|
|
839
|
+
const layoutRscStream = renderRSCStream(
|
|
840
|
+
splicedLayoutTree,
|
|
841
|
+
clientManifest,
|
|
842
|
+
{ runtime: "edge" }
|
|
843
|
+
);
|
|
844
|
+
layoutRscPromise = new Response(layoutRscStream).text();
|
|
845
|
+
}
|
|
846
|
+
const [layoutRscText, pageRscText] = await Promise.all([
|
|
847
|
+
layoutRscPromise,
|
|
848
|
+
new Response(pageRscStream).text(),
|
|
849
|
+
]);
|
|
850
|
+
if (pageRscText && (!hasActiveLayout || layoutRscText)) {
|
|
851
|
+
let rscScripts =
|
|
852
|
+
"\n<script>window.__DINOU_INLINE_RSC__=true;window.__DINOU_RSC_P__=window.__DINOU_RSC_P__||[];window.__DINOU_RSC_L__=window.__DINOU_RSC_L__||[];</script>";
|
|
853
|
+
if (hasActiveLayout && layoutRscText) {
|
|
854
|
+
rscScripts +=
|
|
855
|
+
formatRscPushScript("L", layoutRscText) + formatRscDoneScript("L");
|
|
856
|
+
}
|
|
857
|
+
rscScripts +=
|
|
858
|
+
formatRscPushScript("P", pageRscText) + formatRscDoneScript("P") + "\n";
|
|
859
|
+
await writer.write(encoder.encode(rscScripts));
|
|
860
|
+
}
|
|
861
|
+
} catch (inlineRscErr) {
|
|
862
|
+
if (process.env.DINOU_DEBUG) {
|
|
863
|
+
console.warn("[Dinou PPR] Inline RSC emission error:", inlineRscErr);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
622
867
|
});
|
|
623
868
|
} catch (streamErr) {
|
|
624
869
|
console.error("[Dinou PPR] Runtime streaming resume error:", streamErr);
|
|
@@ -639,12 +884,31 @@ async function handlePprResume({
|
|
|
639
884
|
}
|
|
640
885
|
|
|
641
886
|
const headers = new Headers(bridge.headers);
|
|
887
|
+
if (Array.isArray(bridge.cookies)) {
|
|
888
|
+
for (const c of bridge.cookies) {
|
|
889
|
+
headers.append("Set-Cookie", c);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
642
892
|
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
643
|
-
headers.
|
|
893
|
+
const existingCacheControl = headers.get("Cache-Control");
|
|
894
|
+
if (!existingCacheControl) {
|
|
895
|
+
headers.set("Cache-Control", "no-store, no-cache, must-revalidate, no-transform");
|
|
896
|
+
} else if (!/\bno-transform\b/i.test(existingCacheControl)) {
|
|
897
|
+
headers.set("Cache-Control", `${existingCacheControl}, no-transform`);
|
|
898
|
+
}
|
|
899
|
+
if (!headers.has("Content-Encoding")) {
|
|
900
|
+
headers.set("Content-Encoding", "identity");
|
|
901
|
+
}
|
|
902
|
+
if (!headers.has("X-Accel-Buffering")) {
|
|
903
|
+
headers.set("X-Accel-Buffering", "no");
|
|
904
|
+
}
|
|
644
905
|
|
|
645
906
|
return new Response(readable, {
|
|
646
|
-
status:
|
|
907
|
+
status: bridge._explicitStatusSet
|
|
908
|
+
? bridge.statusCode
|
|
909
|
+
: metadata?.status || 200,
|
|
647
910
|
headers,
|
|
911
|
+
encodeBody: "manual",
|
|
648
912
|
});
|
|
649
913
|
}
|
|
650
914
|
|