dinou 9.0.3 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +520 -503
- package/dinou/cli.js +1 -1
- package/dinou/core/bailout-proxy.js +2 -2
- package/dinou/core/build-static-pages.js +2 -0
- package/dinou/core/cache-revalidate.js +77 -10
- package/dinou/core/cache-slot.js +176 -50
- package/dinou/core/get-jsx.js +405 -333
- package/dinou/core/handler.js +3078 -2983
- package/dinou/core/no-dynamic.js +25 -0
- package/dinou/core/ppr-context.js +500 -256
- package/dinou/core/ppr-runtime.js +660 -540
- package/dinou/core/render-jsx-to-client-jsx.js +576 -44
- 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/index.d.ts +10 -0
- package/dinou/index.js +3 -0
- package/dinou/node/dev.js +2866 -2853
- package/dinou/package.json +4 -4
- 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 +39 -0
- package/dinou/server.js +6 -0
- package/dinou/webpack/loaders/server-functions-loader.js +101 -101
- package/package.json +1 -1
package/dinou/core/get-jsx.js
CHANGED
|
@@ -1,333 +1,405 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
3
|
-
import { existsSync } from "./vfs.js";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import {
|
|
6
|
-
getFilePathAndDynamicParams,
|
|
7
|
-
} from "./get-file-path-and-dynamic-params.js";
|
|
8
|
-
import importModule from "./import-module.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
3
|
+
import { existsSync } from "./vfs.js";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import {
|
|
6
|
+
getFilePathAndDynamicParams,
|
|
7
|
+
} from "./get-file-path-and-dynamic-params.js";
|
|
8
|
+
import importModule from "./import-module.js";
|
|
9
|
+
import {
|
|
10
|
+
asyncRenderJSXToClientJSX,
|
|
11
|
+
replaceLayoutChildrenPlaceholder,
|
|
12
|
+
} from "./render-jsx-to-client-jsx.js";
|
|
13
|
+
import { getLayoutProps } from "./layout-functions.js";
|
|
14
|
+
import { DinouPageSlot as RawDinouPageSlot } from "./slot.js";
|
|
15
|
+
import { getErrorJSX } from "./get-error-jsx.js";
|
|
16
|
+
import {
|
|
17
|
+
markPageRootElement,
|
|
18
|
+
markLayoutRootElement,
|
|
19
|
+
createLayoutChildrenPlaceholder,
|
|
20
|
+
runInPageSegment,
|
|
21
|
+
runInLayoutSegment,
|
|
22
|
+
isPprBuildActive,
|
|
23
|
+
getPprStore,
|
|
24
|
+
} from "./ppr-context.js";
|
|
25
|
+
import { getContext } from "./request-context.js";
|
|
26
|
+
import { createRequire } from "node:module";
|
|
27
|
+
|
|
28
|
+
const require = createRequire(import.meta.url);
|
|
29
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
|
|
31
|
+
async function getJSX(
|
|
32
|
+
reqPath,
|
|
33
|
+
query,
|
|
34
|
+
isNotFound = null,
|
|
35
|
+
isDevelopment = false,
|
|
36
|
+
forceNotFound = false,
|
|
37
|
+
options = {},
|
|
38
|
+
) {
|
|
39
|
+
const srcFolder = path.resolve(process.cwd(), "src");
|
|
40
|
+
const reqSegments = reqPath.split("/").filter(Boolean);
|
|
41
|
+
const normalizedReqPath =
|
|
42
|
+
"/" + reqSegments.join("/") + (reqSegments.length > 0 ? "/" : "");
|
|
43
|
+
|
|
44
|
+
let jsx;
|
|
45
|
+
let pageFunctionsProps;
|
|
46
|
+
|
|
47
|
+
// 1. Segmented handling for Layout: If only the layout is requested
|
|
48
|
+
if (options && options.segment === "layout") {
|
|
49
|
+
let DinouPageSlot = RawDinouPageSlot;
|
|
50
|
+
if (
|
|
51
|
+
typeof DinouPageSlot === "function" &&
|
|
52
|
+
DinouPageSlot.$$typeof !== Symbol.for("react.client.reference")
|
|
53
|
+
) {
|
|
54
|
+
const slotPath = path.resolve(currentDir, "slot.js");
|
|
55
|
+
const fileUrl = pathToFileURL(slotPath).href;
|
|
56
|
+
let regFn = null;
|
|
57
|
+
try {
|
|
58
|
+
const pkg = require("react-server-dom-webpack/server");
|
|
59
|
+
regFn = pkg.registerClientReference;
|
|
60
|
+
} catch (e) {}
|
|
61
|
+
if (!regFn) {
|
|
62
|
+
try {
|
|
63
|
+
const pkg = require("@roggc/react-server-dom-esm/server.node.js");
|
|
64
|
+
regFn = pkg.registerClientReference;
|
|
65
|
+
} catch (e) {}
|
|
66
|
+
}
|
|
67
|
+
if (regFn) {
|
|
68
|
+
DinouPageSlot = regFn(DinouPageSlot, fileUrl, "DinouPageSlot");
|
|
69
|
+
} else {
|
|
70
|
+
Object.defineProperties(DinouPageSlot, {
|
|
71
|
+
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
72
|
+
$$id: { value: fileUrl + "#DinouPageSlot" },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
jsx = React.createElement(DinouPageSlot);
|
|
77
|
+
} else {
|
|
78
|
+
const hasRouterSyntax = reqSegments.some((seg) => {
|
|
79
|
+
const isGroup = seg.startsWith("(") && seg.endsWith(")");
|
|
80
|
+
|
|
81
|
+
const isDynamic = seg.startsWith("[") && seg.endsWith("]");
|
|
82
|
+
const isSlot = seg.startsWith("@");
|
|
83
|
+
const isPrivate = seg.startsWith("_");
|
|
84
|
+
|
|
85
|
+
return isGroup || isDynamic || isSlot || isPrivate;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
let pagePath;
|
|
89
|
+
let folderPath = "";
|
|
90
|
+
if (!hasRouterSyntax) {
|
|
91
|
+
folderPath = path.join(srcFolder, ...reqSegments);
|
|
92
|
+
if (existsSync(folderPath)) {
|
|
93
|
+
for (const ext of [".tsx", ".ts", ".jsx", ".js"]) {
|
|
94
|
+
const candidatePath = path.join(folderPath, `page${ext}`);
|
|
95
|
+
if (existsSync(candidatePath)) {
|
|
96
|
+
pagePath = candidatePath;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
let dynamicParams = {};
|
|
103
|
+
|
|
104
|
+
if (!pagePath) {
|
|
105
|
+
const [filePath, dParams] = getFilePathAndDynamicParams(
|
|
106
|
+
reqSegments,
|
|
107
|
+
query,
|
|
108
|
+
srcFolder,
|
|
109
|
+
);
|
|
110
|
+
pagePath = filePath;
|
|
111
|
+
dynamicParams = dParams ?? {};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!pagePath || forceNotFound) {
|
|
115
|
+
if (isNotFound) isNotFound.value = true;
|
|
116
|
+
const [notFoundPath, dParams] = getFilePathAndDynamicParams(
|
|
117
|
+
reqSegments,
|
|
118
|
+
query,
|
|
119
|
+
srcFolder,
|
|
120
|
+
"not_found",
|
|
121
|
+
true,
|
|
122
|
+
false,
|
|
123
|
+
);
|
|
124
|
+
if (!notFoundPath) {
|
|
125
|
+
jsx = markPageRootElement(
|
|
126
|
+
React.createElement(
|
|
127
|
+
"div",
|
|
128
|
+
null,
|
|
129
|
+
`Page not found: no "page" file found for "${normalizedReqPath}"`,
|
|
130
|
+
),
|
|
131
|
+
);
|
|
132
|
+
} else {
|
|
133
|
+
const pageModule = await importModule(notFoundPath);
|
|
134
|
+
const Page = pageModule.default ?? pageModule;
|
|
135
|
+
let props = {
|
|
136
|
+
params: dParams ?? {},
|
|
137
|
+
};
|
|
138
|
+
const notFoundDir = path.dirname(notFoundPath);
|
|
139
|
+
|
|
140
|
+
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
141
|
+
reqSegments,
|
|
142
|
+
query,
|
|
143
|
+
notFoundDir,
|
|
144
|
+
"page_functions",
|
|
145
|
+
true,
|
|
146
|
+
true,
|
|
147
|
+
undefined,
|
|
148
|
+
reqSegments.length,
|
|
149
|
+
);
|
|
150
|
+
if (pageFunctionsPath) {
|
|
151
|
+
const pageFunctionsModule = await importModule(pageFunctionsPath);
|
|
152
|
+
const defaultExport = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
|
|
153
|
+
const getProps = pageFunctionsModule.getProps || defaultExport?.getProps;
|
|
154
|
+
pageFunctionsProps = await getProps?.(dParams ?? {});
|
|
155
|
+
props = { ...props, ...(pageFunctionsProps ?? {}) };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
jsx = markPageRootElement(React.createElement(Page, props));
|
|
159
|
+
const noLayoutNotFoundPath = path.join(
|
|
160
|
+
notFoundDir,
|
|
161
|
+
`no_layout_not_found`,
|
|
162
|
+
);
|
|
163
|
+
if (existsSync(noLayoutNotFoundPath)) {
|
|
164
|
+
if (
|
|
165
|
+
!isPprBuildActive() &&
|
|
166
|
+
!getPprStore() &&
|
|
167
|
+
!getContext()?._isPprRuntimeResume &&
|
|
168
|
+
!options?.skipLayoutProbe
|
|
169
|
+
) {
|
|
170
|
+
jsx = await runInPageSegment(() => asyncRenderJSXToClientJSX(jsx));
|
|
171
|
+
}
|
|
172
|
+
return jsx;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
if (isNotFound) isNotFound.value = false;
|
|
177
|
+
const pageModule = await importModule(pagePath);
|
|
178
|
+
const Page = pageModule.default ?? pageModule;
|
|
179
|
+
|
|
180
|
+
let props = {
|
|
181
|
+
params: dynamicParams,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const pageFolder = path.dirname(pagePath);
|
|
185
|
+
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
186
|
+
reqSegments,
|
|
187
|
+
query,
|
|
188
|
+
pageFolder,
|
|
189
|
+
"page_functions",
|
|
190
|
+
true,
|
|
191
|
+
true,
|
|
192
|
+
undefined,
|
|
193
|
+
reqSegments.length,
|
|
194
|
+
);
|
|
195
|
+
if (pageFunctionsPath) {
|
|
196
|
+
const pageFunctionsModule = await importModule(pageFunctionsPath);
|
|
197
|
+
const defaultExport = pageFunctionsModule.default?.default ? pageFunctionsModule.default.default : pageFunctionsModule.default;
|
|
198
|
+
const getProps = pageFunctionsModule.getProps || defaultExport?.getProps;
|
|
199
|
+
pageFunctionsProps = await getProps?.(dynamicParams);
|
|
200
|
+
props = { ...props, ...(pageFunctionsProps ?? {}) };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
jsx = markPageRootElement(React.createElement(Page, props));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (
|
|
207
|
+
!isPprBuildActive() &&
|
|
208
|
+
!getPprStore() &&
|
|
209
|
+
!getContext()?._isPprRuntimeResume &&
|
|
210
|
+
!options?.skipLayoutProbe
|
|
211
|
+
) {
|
|
212
|
+
jsx = await runInPageSegment(() => asyncRenderJSXToClientJSX(jsx));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 2. Segmented handling for Page: If only the page is requested, return without layouts
|
|
216
|
+
if (options && options.segment === "page") {
|
|
217
|
+
return jsx;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (
|
|
222
|
+
options?.segment !== "layout" &&
|
|
223
|
+
getFilePathAndDynamicParams(
|
|
224
|
+
reqSegments,
|
|
225
|
+
query,
|
|
226
|
+
srcFolder,
|
|
227
|
+
"no_layout",
|
|
228
|
+
false,
|
|
229
|
+
)[0]
|
|
230
|
+
) {
|
|
231
|
+
return jsx;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const layouts = getFilePathAndDynamicParams(
|
|
235
|
+
reqSegments,
|
|
236
|
+
query,
|
|
237
|
+
srcFolder,
|
|
238
|
+
"layout",
|
|
239
|
+
true,
|
|
240
|
+
false,
|
|
241
|
+
undefined,
|
|
242
|
+
0,
|
|
243
|
+
{},
|
|
244
|
+
true,
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
if (layouts && Array.isArray(layouts)) {
|
|
248
|
+
let index = 0;
|
|
249
|
+
const layoutSegmentStore = { active: true, idCount: 0, holeCount: 0 };
|
|
250
|
+
for (const [layoutPath, dParams, slots] of layouts.reverse()) {
|
|
251
|
+
const layoutModule = await importModule(layoutPath);
|
|
252
|
+
const layoutFolderPath = path.dirname(layoutPath);
|
|
253
|
+
const resetLayoutPath = getFilePathAndDynamicParams(
|
|
254
|
+
[],
|
|
255
|
+
{},
|
|
256
|
+
layoutFolderPath,
|
|
257
|
+
"reset_layout",
|
|
258
|
+
false,
|
|
259
|
+
)[0];
|
|
260
|
+
const Layout = layoutModule.default ?? layoutModule;
|
|
261
|
+
const updatedSlots = {};
|
|
262
|
+
for (const [slotName, slotValue] of Object.entries(slots)) {
|
|
263
|
+
let updatedSlotElement;
|
|
264
|
+
const slotFilePath = slotValue?.slotPath || slotValue?.props?.__modulePath;
|
|
265
|
+
const slotParams = slotValue?.slotParams || slotValue?.props?.params || {};
|
|
266
|
+
const prevSlotIdCount = layoutSegmentStore.idCount;
|
|
267
|
+
const prevSlotHoleCount = layoutSegmentStore.holeCount;
|
|
268
|
+
try {
|
|
269
|
+
let elementToRender;
|
|
270
|
+
if (slotValue && slotValue.slotPath) {
|
|
271
|
+
const slotModule = await importModule(slotValue.slotPath);
|
|
272
|
+
const Slot = slotModule.default ?? slotModule;
|
|
273
|
+
elementToRender = React.createElement(Slot, {
|
|
274
|
+
params: slotParams,
|
|
275
|
+
key: slotName,
|
|
276
|
+
__modulePath: slotValue.slotPath,
|
|
277
|
+
});
|
|
278
|
+
} else {
|
|
279
|
+
elementToRender = slotValue;
|
|
280
|
+
}
|
|
281
|
+
const resolvedSlot = await runInLayoutSegment(
|
|
282
|
+
() => asyncRenderJSXToClientJSX(elementToRender),
|
|
283
|
+
layoutSegmentStore
|
|
284
|
+
);
|
|
285
|
+
updatedSlotElement = isPprBuildActive() ? elementToRender : resolvedSlot;
|
|
286
|
+
} catch (e) {
|
|
287
|
+
layoutSegmentStore.idCount = prevSlotIdCount;
|
|
288
|
+
layoutSegmentStore.holeCount = prevSlotHoleCount;
|
|
289
|
+
if (slotFilePath) {
|
|
290
|
+
const realSlotFolder = path.dirname(slotFilePath);
|
|
291
|
+
|
|
292
|
+
const [slotErrorPath, slotErrorParams] =
|
|
293
|
+
getFilePathAndDynamicParams(
|
|
294
|
+
reqSegments,
|
|
295
|
+
query,
|
|
296
|
+
realSlotFolder,
|
|
297
|
+
"error",
|
|
298
|
+
true, // withExtension
|
|
299
|
+
true, // finalDestination
|
|
300
|
+
undefined, // lastFound
|
|
301
|
+
reqSegments.length,
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
if (slotErrorPath) {
|
|
305
|
+
const slotErrorModule = await importModule(slotErrorPath);
|
|
306
|
+
const SlotError = slotErrorModule.default ?? slotErrorModule;
|
|
307
|
+
|
|
308
|
+
const serializedError = {
|
|
309
|
+
message: e.message || "Unknown Error",
|
|
310
|
+
name: e.name,
|
|
311
|
+
stack: isDevelopment ? e.stack : undefined,
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
updatedSlotElement = React.createElement(SlotError, {
|
|
315
|
+
params: slotErrorParams,
|
|
316
|
+
key: slotName,
|
|
317
|
+
error: serializedError,
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
console.warn(
|
|
321
|
+
`[Dinou] Slot @${slotName} failed and does not have error.tsx`,
|
|
322
|
+
);
|
|
323
|
+
updatedSlotElement = null;
|
|
324
|
+
}
|
|
325
|
+
} else {
|
|
326
|
+
console.error(
|
|
327
|
+
`[Dinou] Could not locate the path of the slot @${slotName}`,
|
|
328
|
+
);
|
|
329
|
+
updatedSlotElement = null;
|
|
330
|
+
}
|
|
331
|
+
} finally {
|
|
332
|
+
updatedSlots[slotName] = updatedSlotElement;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const layoutProps = await getLayoutProps(layoutPath, dParams);
|
|
336
|
+
let props = { params: dParams, ...updatedSlots, ...(layoutProps ?? {}) };
|
|
337
|
+
if (options?.skipLayoutProbe) {
|
|
338
|
+
jsx = markLayoutRootElement(React.createElement(Layout, props, jsx));
|
|
339
|
+
} else if (isPprBuildActive()) {
|
|
340
|
+
try {
|
|
341
|
+
const testElement = React.createElement(Layout, props, null);
|
|
342
|
+
await runInLayoutSegment(() => asyncRenderJSXToClientJSX(testElement));
|
|
343
|
+
jsx = markLayoutRootElement(React.createElement(Layout, props, jsx));
|
|
344
|
+
} catch (layoutErr) {
|
|
345
|
+
console.warn(
|
|
346
|
+
`[Dinou] Layout ${layoutPath} failed during render, isolating layout error:`,
|
|
347
|
+
layoutErr?.message || layoutErr
|
|
348
|
+
);
|
|
349
|
+
const serializedError = {
|
|
350
|
+
message: layoutErr.message || "Unknown Error",
|
|
351
|
+
name: layoutErr.name || "Error",
|
|
352
|
+
stack: isDevelopment ? layoutErr.stack : undefined,
|
|
353
|
+
};
|
|
354
|
+
jsx = await getErrorJSX(
|
|
355
|
+
reqPath,
|
|
356
|
+
query,
|
|
357
|
+
serializedError,
|
|
358
|
+
isDevelopment,
|
|
359
|
+
{ segment: "page" }
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
} else {
|
|
363
|
+
const prevLayoutIdCount = layoutSegmentStore.idCount;
|
|
364
|
+
const prevLayoutHoleCount = layoutSegmentStore.holeCount;
|
|
365
|
+
try {
|
|
366
|
+
const placeholder = createLayoutChildrenPlaceholder();
|
|
367
|
+
const testElement = React.createElement(Layout, props, placeholder);
|
|
368
|
+
const resolvedLayout = await runInLayoutSegment(
|
|
369
|
+
() => asyncRenderJSXToClientJSX(testElement),
|
|
370
|
+
layoutSegmentStore
|
|
371
|
+
);
|
|
372
|
+
jsx = replaceLayoutChildrenPlaceholder(resolvedLayout, jsx, placeholder);
|
|
373
|
+
} catch (layoutErr) {
|
|
374
|
+
layoutSegmentStore.idCount = prevLayoutIdCount;
|
|
375
|
+
layoutSegmentStore.holeCount = prevLayoutHoleCount;
|
|
376
|
+
console.warn(
|
|
377
|
+
`[Dinou] Layout ${layoutPath} failed during render, isolating layout error:`,
|
|
378
|
+
layoutErr?.message || layoutErr
|
|
379
|
+
);
|
|
380
|
+
const serializedError = {
|
|
381
|
+
message: layoutErr.message || "Unknown Error",
|
|
382
|
+
name: layoutErr.name || "Error",
|
|
383
|
+
stack: isDevelopment ? layoutErr.stack : undefined,
|
|
384
|
+
};
|
|
385
|
+
jsx = await getErrorJSX(
|
|
386
|
+
reqPath,
|
|
387
|
+
query,
|
|
388
|
+
serializedError,
|
|
389
|
+
isDevelopment,
|
|
390
|
+
{ segment: "page" }
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (resetLayoutPath) {
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
index++;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return jsx;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export { getJSX };
|
|
405
|
+
export default getJSX;
|