dinou 9.0.1 → 9.0.3

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +503 -9883
  3. package/dinou/bun/build.js +38 -1
  4. package/{cli.js → dinou/cli.js} +14 -7
  5. package/dinou/cloudflare/build.js +37 -0
  6. package/dinou/core/build-static-pages.js +15 -7
  7. package/dinou/core/cache-revalidate.js +909 -151
  8. package/dinou/core/cache-slot.js +728 -97
  9. package/dinou/core/client-webpack.jsx +60 -9
  10. package/dinou/core/client.jsx +60 -9
  11. package/dinou/core/edge-ssr.js +33 -5
  12. package/dinou/core/generate-static.js +109 -47
  13. package/dinou/core/get-jsx.js +333 -329
  14. package/dinou/core/handler.js +2983 -2343
  15. package/dinou/core/layout-functions.js +102 -1
  16. package/dinou/core/ppr-context.js +256 -105
  17. package/dinou/core/ppr-runtime.js +540 -267
  18. package/dinou/core/render-jsx-to-client-jsx.js +131 -71
  19. package/dinou/core/slot.js +246 -33
  20. package/dinou/core/storage-adapter.js +117 -11
  21. package/dinou/deno/build.js +38 -1
  22. package/dinou/deno/seed-kv.js +43 -11
  23. package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +242 -225
  24. package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +253 -226
  25. package/dinou/esbuild/react-refresh/esm-hmr/client.js +209 -209
  26. package/dinou/node/build.js +2 -2
  27. package/dinou/node/bundle-dual-engine.js +2 -0
  28. package/dinou/node/dev.js +2853 -2704
  29. package/dinou/package.json +5 -2
  30. package/dinou/rollup/react-refresh/esm-hmr/client.js +220 -220
  31. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +182 -160
  32. package/dinou/server.d.ts +25 -11
  33. package/dinou/server.js +5 -0
  34. package/dinou/webpack/loaders/server-functions-loader.js +101 -94
  35. package/dinou/webpack/webpack.config.js +9 -4
  36. package/eject.js +219 -223
  37. package/package.json +2 -2
@@ -58,7 +58,30 @@ const scrollToCurrentHash = (rawHash = typeof window !== "undefined" ? window.lo
58
58
 
59
59
  // Helper to determine active layout folder for a pathname
60
60
  const getLayoutKey = (pathname) => {
61
- const layouts = (typeof window !== "undefined" && window.__DINOU_LAYOUTS__) || ["", "docs"];
61
+ const rawLayouts = (typeof window !== "undefined" && window.__DINOU_LAYOUTS__) || ["", "docs"];
62
+ const layouts = rawLayouts.filter((l) => typeof l === "string" && !l.startsWith("!"));
63
+ const noLayouts = rawLayouts
64
+ .filter((l) => typeof l === "string" && l.startsWith("!"))
65
+ .map((l) => l.slice(1));
66
+ const cleanPath0 = pathname.split("?")[0].split("#")[0];
67
+ const segments0 = cleanPath0.split("/").filter(Boolean);
68
+ const fullCandidate = segments0.join("/");
69
+ if (
70
+ noLayouts.includes(fullCandidate) ||
71
+ noLayouts.some((nl) => {
72
+ const lSegs = nl
73
+ .split("/")
74
+ .filter(Boolean)
75
+ .filter((seg) => !(seg.startsWith("(") && seg.endsWith(")")));
76
+ if (lSegs.length !== segments0.length) return false;
77
+ return lSegs.every((seg, idx) => {
78
+ if (seg.startsWith("[") && seg.endsWith("]")) return true;
79
+ return seg === segments0[idx];
80
+ });
81
+ })
82
+ ) {
83
+ return null;
84
+ }
62
85
  const cleanPath = pathname.split("?")[0].split("#")[0];
63
86
  const segments = cleanPath.split("/").filter(Boolean);
64
87
 
@@ -114,7 +137,7 @@ const isHashChangeOnly = (finalPath) => {
114
137
  );
115
138
  };
116
139
 
117
- const getPagePayload = (route, isPrefetch = false) => {
140
+ const getPagePayload = (route, isPrefetch = false, version = 0) => {
118
141
  const url = route.split("::")[0];
119
142
  if (pageCache.has(url)) {
120
143
  return pageCache.get(url);
@@ -133,9 +156,16 @@ const getPagePayload = (route, isPrefetch = false) => {
133
156
  payloadUrl = "/____rsc_page____" + url;
134
157
  }
135
158
 
136
- const buildId = window.__DINOU_BUILD_ID__;
137
- if (buildId) {
138
- payloadUrl += (payloadUrl.includes("?") ? "&" : "?") + "buildId=" + buildId;
159
+ const isInitialHydration =
160
+ !isPrefetch &&
161
+ typeof document !== "undefined" &&
162
+ (!document.body || document.body.getAttribute("data-hydrated") !== "true");
163
+ const buildId = isInitialHydration ? window.__DINOU_BUILD_ID__ : undefined;
164
+ if (buildId && !version) {
165
+ payloadUrl += (payloadUrl.includes("?") ? "&" : "?") + "____build_id____=" + buildId;
166
+ }
167
+ if (version) {
168
+ payloadUrl += (payloadUrl.includes("?") ? "&" : "?") + "____v____=" + version;
139
169
  }
140
170
 
141
171
  const promise = createFromFetch(
@@ -174,14 +204,22 @@ const getLayoutPayload = (layoutKey, searchPart = "", version = 0) => {
174
204
  return layoutCache.get(cacheKey);
175
205
  }
176
206
 
207
+ const isInitialHydration =
208
+ typeof document !== "undefined" &&
209
+ (!document.body || document.body.getAttribute("data-hydrated") !== "true");
210
+ const buildId = isInitialHydration ? window.__DINOU_BUILD_ID__ : undefined;
177
211
  const cleanKey = layoutKey === "/" ? "" : layoutKey;
178
212
  let layoutUrl =
179
213
  (window.__DINOU_USE_STATIC__
180
214
  ? "/____rsc_layout_static____"
181
215
  : "/____rsc_layout____") + cleanKey + searchPart;
182
216
 
217
+ if (buildId && !version) {
218
+ layoutUrl += (layoutUrl.includes("?") ? "&" : "?") + "____build_id____=" + buildId;
219
+ }
220
+
183
221
  if (version) {
184
- layoutUrl += (layoutUrl.includes("?") ? "&" : "?") + "v=" + version;
222
+ layoutUrl += (layoutUrl.includes("?") ? "&" : "?") + "____v____=" + version;
185
223
  }
186
224
 
187
225
  const promise = createFromFetch(
@@ -252,9 +290,12 @@ const getErrorRSCPayload = (route, error) => {
252
290
  };
253
291
 
254
292
  const fetchSlotRSC = (slotId, options = {}) => {
255
- const currentPath = typeof window !== "undefined" ? window.location.pathname : "/";
293
+ const currentPath =
294
+ (options && options.currentPath) ||
295
+ (typeof window !== "undefined" ? window.location.pathname : "/");
256
296
  const freshQuery = options && options.fresh ? "&fresh=1" : "";
257
- const slotUrl = `/____rsc_slot____/${slotId}?t=${Date.now()}${freshQuery}`;
297
+ const slotSeq = (window.__DINOU_SLOT_SEQ__ = (window.__DINOU_SLOT_SEQ__ || 0) + 1);
298
+ const slotUrl = `/____rsc_slot____/${slotId}?t=${Date.now()}-${slotSeq}${freshQuery}`;
258
299
  return createFromFetch(
259
300
  fetch(slotUrl, {
260
301
  headers: {
@@ -679,9 +720,19 @@ function Router() {
679
720
  return initialPageErrorRef.current;
680
721
  }
681
722
  if (navError) return getErrorRSCPayload(route, navError);
682
- return getPagePayload(route + (version ? `?v=${version}` : ""));
723
+ return getPagePayload(route, false, version);
683
724
  }, [route, version, navError]);
684
725
 
726
+ useLayoutEffect(() => {
727
+ if (
728
+ typeof document !== "undefined" &&
729
+ document.body &&
730
+ document.body.getAttribute("data-hydrated") !== "true"
731
+ ) {
732
+ document.body.setAttribute("data-hydrated", "true");
733
+ }
734
+ });
735
+
685
736
  const layoutPromise = useMemo(() => {
686
737
  return layoutKey !== null
687
738
  ? getLayoutPayload(layoutKey, searchPart, layoutVersion)
@@ -58,7 +58,30 @@ const scrollToCurrentHash = (rawHash = typeof window !== "undefined" ? window.lo
58
58
 
59
59
  // Helper to determine active layout folder for a pathname
60
60
  const getLayoutKey = (pathname) => {
61
- const layouts = (typeof window !== "undefined" && window.__DINOU_LAYOUTS__) || ["", "docs"];
61
+ const rawLayouts = (typeof window !== "undefined" && window.__DINOU_LAYOUTS__) || ["", "docs"];
62
+ const layouts = rawLayouts.filter((l) => typeof l === "string" && !l.startsWith("!"));
63
+ const noLayouts = rawLayouts
64
+ .filter((l) => typeof l === "string" && l.startsWith("!"))
65
+ .map((l) => l.slice(1));
66
+ const cleanPath0 = pathname.split("?")[0].split("#")[0];
67
+ const segments0 = cleanPath0.split("/").filter(Boolean);
68
+ const fullCandidate = segments0.join("/");
69
+ if (
70
+ noLayouts.includes(fullCandidate) ||
71
+ noLayouts.some((nl) => {
72
+ const lSegs = nl
73
+ .split("/")
74
+ .filter(Boolean)
75
+ .filter((seg) => !(seg.startsWith("(") && seg.endsWith(")")));
76
+ if (lSegs.length !== segments0.length) return false;
77
+ return lSegs.every((seg, idx) => {
78
+ if (seg.startsWith("[") && seg.endsWith("]")) return true;
79
+ return seg === segments0[idx];
80
+ });
81
+ })
82
+ ) {
83
+ return null;
84
+ }
62
85
  const cleanPath = pathname.split("?")[0].split("#")[0];
63
86
  const segments = cleanPath.split("/").filter(Boolean);
64
87
 
@@ -114,7 +137,7 @@ const isHashChangeOnly = (finalPath) => {
114
137
  );
115
138
  };
116
139
 
117
- const getPagePayload = (route, isPrefetch = false) => {
140
+ const getPagePayload = (route, isPrefetch = false, version = 0) => {
118
141
  const url = route.split("::")[0];
119
142
  if (pageCache.has(url)) {
120
143
  return pageCache.get(url);
@@ -133,9 +156,16 @@ const getPagePayload = (route, isPrefetch = false) => {
133
156
  payloadUrl = "/____rsc_page____" + url;
134
157
  }
135
158
 
136
- const buildId = window.__DINOU_BUILD_ID__;
137
- if (buildId) {
138
- payloadUrl += (payloadUrl.includes("?") ? "&" : "?") + "buildId=" + buildId;
159
+ const isInitialHydration =
160
+ !isPrefetch &&
161
+ typeof document !== "undefined" &&
162
+ (!document.body || document.body.getAttribute("data-hydrated") !== "true");
163
+ const buildId = isInitialHydration ? window.__DINOU_BUILD_ID__ : undefined;
164
+ if (buildId && !version) {
165
+ payloadUrl += (payloadUrl.includes("?") ? "&" : "?") + "____build_id____=" + buildId;
166
+ }
167
+ if (version) {
168
+ payloadUrl += (payloadUrl.includes("?") ? "&" : "?") + "____v____=" + version;
139
169
  }
140
170
 
141
171
  const promise = createFromFetch(
@@ -174,14 +204,22 @@ const getLayoutPayload = (layoutKey, searchPart = "", version = 0) => {
174
204
  return layoutCache.get(cacheKey);
175
205
  }
176
206
 
207
+ const isInitialHydration =
208
+ typeof document !== "undefined" &&
209
+ (!document.body || document.body.getAttribute("data-hydrated") !== "true");
210
+ const buildId = isInitialHydration ? window.__DINOU_BUILD_ID__ : undefined;
177
211
  const cleanKey = layoutKey === "/" ? "" : layoutKey;
178
212
  let layoutUrl =
179
213
  (window.__DINOU_USE_STATIC__
180
214
  ? "/____rsc_layout_static____"
181
215
  : "/____rsc_layout____") + cleanKey + searchPart;
182
216
 
217
+ if (buildId && !version) {
218
+ layoutUrl += (layoutUrl.includes("?") ? "&" : "?") + "____build_id____=" + buildId;
219
+ }
220
+
183
221
  if (version) {
184
- layoutUrl += (layoutUrl.includes("?") ? "&" : "?") + "v=" + version;
222
+ layoutUrl += (layoutUrl.includes("?") ? "&" : "?") + "____v____=" + version;
185
223
  }
186
224
 
187
225
  const promise = createFromFetch(
@@ -252,9 +290,12 @@ const getErrorRSCPayload = (route, error) => {
252
290
  };
253
291
 
254
292
  const fetchSlotRSC = (slotId, options = {}) => {
255
- const currentPath = typeof window !== "undefined" ? window.location.pathname : "/";
293
+ const currentPath =
294
+ (options && options.currentPath) ||
295
+ (typeof window !== "undefined" ? window.location.pathname : "/");
256
296
  const freshQuery = options && options.fresh ? "&fresh=1" : "";
257
- const slotUrl = `/____rsc_slot____/${slotId}?t=${Date.now()}${freshQuery}`;
297
+ const slotSeq = (window.__DINOU_SLOT_SEQ__ = (window.__DINOU_SLOT_SEQ__ || 0) + 1);
298
+ const slotUrl = `/____rsc_slot____/${slotId}?t=${Date.now()}-${slotSeq}${freshQuery}`;
258
299
  return createFromFetch(
259
300
  fetch(slotUrl, {
260
301
  headers: {
@@ -680,9 +721,19 @@ function Router() {
680
721
  return initialPageErrorRef.current;
681
722
  }
682
723
  if (navError) return getErrorRSCPayload(route, navError);
683
- return getPagePayload(route + (version ? `?v=${version}` : ""));
724
+ return getPagePayload(route, false, version);
684
725
  }, [route, version, navError]);
685
726
 
727
+ useLayoutEffect(() => {
728
+ if (
729
+ typeof document !== "undefined" &&
730
+ document.body &&
731
+ document.body.getAttribute("data-hydrated") !== "true"
732
+ ) {
733
+ document.body.setAttribute("data-hydrated", "true");
734
+ }
735
+ });
736
+
686
737
  const layoutPromise = useMemo(() => {
687
738
  return layoutKey !== null
688
739
  ? getLayoutPayload(layoutKey, searchPart, layoutVersion)
@@ -2,14 +2,16 @@
2
2
  // Native React 19 Edge SSR Streaming Engine for Dinou.
3
3
  // Reconstructs React element tree from RSC stream and renders native HTML stream via react-dom/server.edge.
4
4
 
5
+ import React from "react";
5
6
  import { createFromReadableStream } from "react-server-dom-webpack/client.edge";
6
7
  import { renderToReadableStream } from "react-dom/server.edge";
8
+ import { DinouPageContext } from "./slot.js";
7
9
 
8
10
  /**
9
11
  * Reconstructs an RSC stream into a React element tree and streams HTML via react-dom/server.edge.
10
12
  * @param {ReadableStream} rscStream The RSC binary stream
11
13
  * @param {object} consumerManifest The client components consumer manifest ({ moduleMap, serverModuleMap, moduleLoading })
12
- * @param {object} options Configuration options ({ bootstrapModules, bootstrapScriptContent, onError, waitForAll })
14
+ * @param {object} options Configuration options ({ bootstrapModules, bootstrapScriptContent, onError, waitForAll, pageRscStream })
13
15
  * @returns {Promise<ReadableStream>} The HTML stream
14
16
  */
15
17
  export async function renderRscStreamToHtmlStream(rscStream, consumerManifest, options = {}) {
@@ -73,10 +75,36 @@ export async function renderRscStreamToHtmlStream(rscStream, consumerManifest, o
73
75
  effectiveManifest = { ...effectiveManifest, serverModuleMap: null };
74
76
  }
75
77
 
76
- // 1. Reconstruct JSX element tree from RSC wire stream
77
- const elementTree = await createFromReadableStream(rscStream, {
78
- serverConsumerManifest: effectiveManifest,
79
- });
78
+ // 1. Reconstruct JSX element tree from RSC wire stream(s)
79
+ let elementTree;
80
+ if (options.pageRscStream) {
81
+ const [layoutTree, pageTree] = await Promise.all([
82
+ createFromReadableStream(rscStream, {
83
+ serverConsumerManifest: effectiveManifest,
84
+ }),
85
+ createFromReadableStream(options.pageRscStream, {
86
+ serverConsumerManifest: effectiveManifest,
87
+ }),
88
+ ]);
89
+ const slotValue = {
90
+ pageElement: pageTree,
91
+ pagePromise: Promise.resolve(pageTree),
92
+ resetKey: "ssr",
93
+ };
94
+ if (typeof globalThis !== "undefined") {
95
+ globalThis.__DINOU_SSR_SLOT_CONTEXT__ = slotValue;
96
+ }
97
+ elementTree = DinouPageContext
98
+ ? React.createElement(DinouPageContext.Provider, { value: slotValue }, layoutTree)
99
+ : layoutTree;
100
+ } else {
101
+ if (typeof globalThis !== "undefined") {
102
+ globalThis.__DINOU_SSR_SLOT_CONTEXT__ = null;
103
+ }
104
+ elementTree = await createFromReadableStream(rscStream, {
105
+ serverConsumerManifest: effectiveManifest,
106
+ });
107
+ }
80
108
 
81
109
  // 2. Stream HTML using React 19's native Edge renderer
82
110
  const htmlStream = await renderToReadableStream(elementTree, {
@@ -72,29 +72,66 @@ async function generateStatic() {
72
72
  const layoutReq = new Request(`http://localhost/____rsc_layout____${layoutReqPath}`);
73
73
  const layoutRes = await rscModule.handleRequest(layoutReq, {
74
74
  runtime: "node-bundle",
75
+ isSSG: true,
75
76
  });
76
- if (layoutRes.status === 200) {
77
+ if (
78
+ layoutRes.status === 200 &&
79
+ !layoutRes.headers.has("x-rsc-redirect") &&
80
+ !layoutRes.headers.has("location")
81
+ ) {
77
82
  const layoutRscText = await layoutRes.text();
78
- const cleanLayoutPath = layoutReqPath.replace(/^\/+/, "").replace(/\/+$/, "");
79
- const layoutRscKey = cleanLayoutPath ? `${cleanLayoutPath}/layout.rsc` : "layout.rsc";
80
-
81
- let layoutMeta = {
82
- status: 200,
83
- generatedAt: Date.now(),
84
- revalidate: undefined,
85
- tags: [],
86
- };
87
- try {
88
- const layoutConfig = await resolveLayoutFunctionsConfig(
89
- layoutInfo.layoutPath,
90
- layoutInfo.params || {}
91
- );
92
- layoutMeta.revalidate = layoutConfig.revalidate;
93
- layoutMeta.tags = layoutConfig.tags || [];
94
- } catch (e) {}
83
+ if (layoutRscText && layoutRscText.trim().length > 0) {
84
+ const cleanLayoutPath = layoutReqPath.replace(/^\/+/, "").replace(/\/+$/, "");
85
+ const layoutRscKey = cleanLayoutPath ? `${cleanLayoutPath}/layout.rsc` : "layout.rsc";
86
+
87
+ let layoutMeta = {
88
+ status: 200,
89
+ generatedAt: Date.now(),
90
+ revalidate: undefined,
91
+ tags: [],
92
+ };
93
+ try {
94
+ const layoutConfig = await resolveLayoutFunctionsConfig(
95
+ layoutInfo.layoutPath,
96
+ layoutInfo.params || {}
97
+ );
98
+ layoutMeta.revalidate = layoutConfig.revalidate;
99
+ layoutMeta.tags = layoutConfig.tags || [];
100
+ if (layoutConfig.ppr !== null && layoutConfig.ppr !== undefined) {
101
+ layoutMeta.ppr = Boolean(layoutConfig.ppr);
102
+ }
103
+ } catch (e) {}
95
104
 
96
- await storage.set(layoutRscKey, layoutRscText, layoutMeta);
97
- } else {
105
+ try {
106
+ const slotTagsHeader = layoutRes.headers.get("x-dinou-slot-tags");
107
+ if (slotTagsHeader) {
108
+ const parsedSlotTags = JSON.parse(slotTagsHeader);
109
+ if (Array.isArray(parsedSlotTags) && parsedSlotTags.length > 0) {
110
+ layoutMeta.slotTags = parsedSlotTags;
111
+ }
112
+ }
113
+ const holesHeader = layoutRes.headers.get("x-dinou-ppr-holes");
114
+ if (holesHeader) {
115
+ const parsedHoles = JSON.parse(holesHeader);
116
+ if (Array.isArray(parsedHoles) && parsedHoles.length > 0) {
117
+ layoutMeta.holes = parsedHoles;
118
+ }
119
+ }
120
+ const suspenseCountHeader = layoutRes.headers.get("x-dinou-suspense-count");
121
+ if (suspenseCountHeader !== null) {
122
+ layoutMeta.suspenseCount = Number(suspenseCountHeader) || 0;
123
+ }
124
+ if (layoutRes.headers.get("x-dinou-dynamic") === "true") {
125
+ layoutMeta.dynamic = true;
126
+ }
127
+ } catch (e) {}
128
+
129
+ await storage.set(layoutRscKey, layoutRscText, layoutMeta);
130
+ }
131
+ } else if (
132
+ !layoutRes.headers.has("x-rsc-redirect") &&
133
+ !layoutRes.headers.has("location")
134
+ ) {
98
135
  const layoutResult = await generateStaticLayoutRSC(
99
136
  layoutReqPath,
100
137
  layoutInfo.layoutPath
@@ -154,8 +191,16 @@ async function generateStatic() {
154
191
  const metaKey = cleanPagePath ? `${cleanPagePath}/metadata.json` : "metadata.json";
155
192
 
156
193
  const htmlItem = await storage.get(indexHtmlKey);
194
+ const effectiveHoles =
195
+ Array.isArray(htmlItem?.metadata?.holes) && htmlItem.metadata.holes.length > 0
196
+ ? htmlItem.metadata.holes
197
+ : routeMeta.holes || [];
157
198
  if (htmlItem) {
158
- await storage.set(shellHtmlKey, htmlItem.content, { ...(htmlItem.metadata || {}), ppr: true, holes: routeMeta.holes || [] });
199
+ await storage.set(shellHtmlKey, htmlItem.content, {
200
+ ...(htmlItem.metadata || {}),
201
+ ppr: true,
202
+ holes: effectiveHoles,
203
+ });
159
204
  }
160
205
  const metaItem = await storage.get(metaKey);
161
206
  let metaObj = {};
@@ -163,7 +208,10 @@ async function generateStatic() {
163
208
  metaObj = metaItem ? JSON.parse(metaItem.content || "{}") : {};
164
209
  } catch (e) {}
165
210
  metaObj.ppr = true;
166
- metaObj.holes = routeMeta.holes || [];
211
+ metaObj.holes =
212
+ Array.isArray(metaObj.holes) && metaObj.holes.length > 0
213
+ ? metaObj.holes
214
+ : effectiveHoles;
167
215
  await storage.set(metaKey, JSON.stringify(metaObj));
168
216
  }
169
217
  } else {
@@ -172,21 +220,46 @@ async function generateStatic() {
172
220
  }
173
221
  }
174
222
 
175
- // B. Pre-render isolated page RSC segment (page.rsc)
176
- try {
177
- const pageReq = new Request(`http://localhost/____rsc_page____${reqPath}`);
178
- const pageRes = await rscModule.handleRequest(pageReq, {
179
- runtime: "node-bundle",
180
- });
181
- if (pageRes.status === 200) {
182
- const pageRscText = await pageRes.text();
183
- const pageRscKey = cleanPagePath ? `${cleanPagePath}/page.rsc` : "page.rsc";
184
- await storage.set(pageRscKey, pageRscText);
185
- if (isRoutePpr) {
186
- const shellRscKey = cleanPagePath ? `${cleanPagePath}/shell.rsc` : "shell.rsc";
187
- await storage.set(shellRscKey, pageRscText, { ppr: true });
223
+ // B. Pre-render isolated page RSC segment (page.rsc) if not already persisted in Step 5A
224
+ const pageRscKey = cleanPagePath ? `${cleanPagePath}/page.rsc` : "page.rsc";
225
+ const existingPageRsc = await storage.get(pageRscKey);
226
+ if (!existingPageRsc || !existingPageRsc.content) {
227
+ try {
228
+ const pageReq = new Request(`http://localhost/____rsc_page____${reqPath}`);
229
+ const pageRes = await rscModule.handleRequest(pageReq, {
230
+ runtime: "node-bundle",
231
+ isSSG: true,
232
+ });
233
+ if (
234
+ pageRes.status === 200 &&
235
+ !pageRes.headers.has("x-rsc-redirect") &&
236
+ !pageRes.headers.has("location")
237
+ ) {
238
+ const pageRscText = await pageRes.text();
239
+ if (pageRscText && pageRscText.trim().length > 0) {
240
+ await storage.set(pageRscKey, pageRscText);
241
+ if (isRoutePpr) {
242
+ const shellRscKey = cleanPagePath ? `${cleanPagePath}/shell.rsc` : "shell.rsc";
243
+ await storage.set(shellRscKey, pageRscText);
244
+ }
245
+ }
246
+ } else if (
247
+ res.status === 200 &&
248
+ !pageRes.headers.has("x-rsc-redirect") &&
249
+ !pageRes.headers.has("location")
250
+ ) {
251
+ const pageResult = await generateStaticPageRSC(reqPath);
252
+ if (
253
+ pageResult &&
254
+ pageResult.tempPath &&
255
+ pageResult.finalPath &&
256
+ existsSync(pageResult.tempPath)
257
+ ) {
258
+ mkdirSync(path.dirname(pageResult.finalPath), { recursive: true });
259
+ renameSync(pageResult.tempPath, pageResult.finalPath);
260
+ }
188
261
  }
189
- } else {
262
+ } catch (pageErr) {
190
263
  const pageResult = await generateStaticPageRSC(reqPath);
191
264
  if (
192
265
  pageResult &&
@@ -198,17 +271,6 @@ async function generateStatic() {
198
271
  renameSync(pageResult.tempPath, pageResult.finalPath);
199
272
  }
200
273
  }
201
- } catch (pageErr) {
202
- const pageResult = await generateStaticPageRSC(reqPath);
203
- if (
204
- pageResult &&
205
- pageResult.tempPath &&
206
- pageResult.finalPath &&
207
- existsSync(pageResult.tempPath)
208
- ) {
209
- mkdirSync(path.dirname(pageResult.finalPath), { recursive: true });
210
- renameSync(pageResult.tempPath, pageResult.finalPath);
211
- }
212
274
  }
213
275
  } catch (err) {
214
276
  console.error(`❌ [SSG] Error pre-rendering ${reqPath}:`, err);