dinou 4.0.3 → 4.0.5
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 +19 -0
- package/README.md +112 -2
- package/dinou/core/build-static-pages.js +257 -261
- package/dinou/core/client-error-webpack.jsx +7 -5
- package/dinou/core/client-error.jsx +7 -5
- package/dinou/core/client-webpack.jsx +8 -6
- package/dinou/core/client.jsx +8 -6
- package/dinou/core/server-function-proxy-webpack.js +23 -7
- package/dinou/core/server-function-proxy.js +22 -6
- package/dinou/core/server.js +51 -1
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.mjs +2 -0
- package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.mjs +64 -0
- package/dinou/esbuild/react-refresh/esm-hmr-plugin.mjs +42 -48
- package/dinou/package.json +5 -2
- package/dinou/rollup/rollup.config.js +6 -1
- package/dinou/webpack/helpers/get-webpack-entries.js +37 -8
- package/dinou/webpack/loaders/server-functions-loader.js +5 -10
- package/dinou/webpack/webpack.config.js +45 -36
- package/package.json +5 -2
|
@@ -42,7 +42,7 @@ function createBailoutProxy(target, label, onBailout) {
|
|
|
42
42
|
|
|
43
43
|
// 🚨 ALARM: Access detected
|
|
44
44
|
console.log(
|
|
45
|
-
`[StaticBailout] Access to ${label} detected: "${String(prop)}"
|
|
45
|
+
`[StaticBailout] Access to ${label} detected: "${String(prop)}".`,
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
// Execute logic to mark as dynamic
|
|
@@ -61,7 +61,7 @@ function createBailoutProxy(target, label, onBailout) {
|
|
|
61
61
|
// Optional: Detect if they try to ask "prop in headers"
|
|
62
62
|
has(t, prop) {
|
|
63
63
|
console.log(
|
|
64
|
-
`[StaticBailout] Existence check (IN) in ${label}: "${String(prop)}"
|
|
64
|
+
`[StaticBailout] Existence check (IN) in ${label}: "${String(prop)}".`,
|
|
65
65
|
);
|
|
66
66
|
onBailout();
|
|
67
67
|
return Reflect.has(t, prop);
|
|
@@ -87,7 +87,7 @@ async function buildStaticPages() {
|
|
|
87
87
|
segments = [],
|
|
88
88
|
params = {},
|
|
89
89
|
dynamicStructure = [],
|
|
90
|
-
doNotPushAtEnd = false
|
|
90
|
+
doNotPushAtEnd = false,
|
|
91
91
|
) {
|
|
92
92
|
const entries = readdirSync(currentPath, { withFileTypes: true });
|
|
93
93
|
const pages = [];
|
|
@@ -101,8 +101,8 @@ async function buildStaticPages() {
|
|
|
101
101
|
segments,
|
|
102
102
|
params,
|
|
103
103
|
dynamicStructure,
|
|
104
|
-
doNotPushAtEnd
|
|
105
|
-
))
|
|
104
|
+
doNotPushAtEnd,
|
|
105
|
+
)),
|
|
106
106
|
);
|
|
107
107
|
} else if (
|
|
108
108
|
entry.name.startsWith("[[...") &&
|
|
@@ -118,7 +118,7 @@ async function buildStaticPages() {
|
|
|
118
118
|
true,
|
|
119
119
|
true,
|
|
120
120
|
undefined,
|
|
121
|
-
segments.length
|
|
121
|
+
segments.length,
|
|
122
122
|
);
|
|
123
123
|
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
124
124
|
segments,
|
|
@@ -128,7 +128,7 @@ async function buildStaticPages() {
|
|
|
128
128
|
true,
|
|
129
129
|
true,
|
|
130
130
|
undefined,
|
|
131
|
-
segments.length
|
|
131
|
+
segments.length,
|
|
132
132
|
);
|
|
133
133
|
|
|
134
134
|
let dynamic, getStaticPaths;
|
|
@@ -143,7 +143,7 @@ async function buildStaticPages() {
|
|
|
143
143
|
console.log(
|
|
144
144
|
`Found optional catch-all route: ${
|
|
145
145
|
segments.join("/") ?? ""
|
|
146
|
-
}/[[...${paramName}]]
|
|
146
|
+
}/[[...${paramName}]]`,
|
|
147
147
|
);
|
|
148
148
|
try {
|
|
149
149
|
if (getStaticPaths) {
|
|
@@ -194,7 +194,7 @@ async function buildStaticPages() {
|
|
|
194
194
|
// If this is undefined, we check if there is something defined to the right
|
|
195
195
|
const remaining = flatSegments.slice(index + 1);
|
|
196
196
|
return remaining.some(
|
|
197
|
-
(s) => s !== undefined && s !== null && s !== ""
|
|
197
|
+
(s) => s !== undefined && s !== null && s !== "",
|
|
198
198
|
);
|
|
199
199
|
});
|
|
200
200
|
|
|
@@ -205,7 +205,7 @@ async function buildStaticPages() {
|
|
|
205
205
|
// 🛡️ 3. URL CLEANING
|
|
206
206
|
// Remove undefineds for the physical URL
|
|
207
207
|
const validSegmentsToAdd = flatSegments.filter(
|
|
208
|
-
(s) => s !== undefined && s !== null && s !== ""
|
|
208
|
+
(s) => s !== undefined && s !== null && s !== "",
|
|
209
209
|
);
|
|
210
210
|
|
|
211
211
|
// 🛡️ 4. PARAMS PREPARATION & NORMALIZATION
|
|
@@ -229,8 +229,8 @@ async function buildStaticPages() {
|
|
|
229
229
|
...(await collectPages(
|
|
230
230
|
dynamicPath,
|
|
231
231
|
[...segments, ...validSegmentsToAdd],
|
|
232
|
-
{ ...params, ...paramsToAdd }
|
|
233
|
-
))
|
|
232
|
+
{ ...params, ...paramsToAdd },
|
|
233
|
+
)),
|
|
234
234
|
);
|
|
235
235
|
}
|
|
236
236
|
}
|
|
@@ -245,8 +245,8 @@ async function buildStaticPages() {
|
|
|
245
245
|
segments,
|
|
246
246
|
params,
|
|
247
247
|
[...dynamicStructure, paramName],
|
|
248
|
-
true
|
|
249
|
-
))
|
|
248
|
+
true,
|
|
249
|
+
)),
|
|
250
250
|
);
|
|
251
251
|
}
|
|
252
252
|
} else if (entry.name.startsWith("[...") && entry.name.endsWith("]")) {
|
|
@@ -260,7 +260,7 @@ async function buildStaticPages() {
|
|
|
260
260
|
true,
|
|
261
261
|
true,
|
|
262
262
|
undefined,
|
|
263
|
-
segments.length
|
|
263
|
+
segments.length,
|
|
264
264
|
);
|
|
265
265
|
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
266
266
|
segments,
|
|
@@ -270,7 +270,7 @@ async function buildStaticPages() {
|
|
|
270
270
|
true,
|
|
271
271
|
true,
|
|
272
272
|
undefined,
|
|
273
|
-
segments.length
|
|
273
|
+
segments.length,
|
|
274
274
|
);
|
|
275
275
|
|
|
276
276
|
let dynamic, getStaticPaths;
|
|
@@ -285,7 +285,7 @@ async function buildStaticPages() {
|
|
|
285
285
|
console.log(
|
|
286
286
|
`Found catch-all route: ${
|
|
287
287
|
segments.join("/") ?? ""
|
|
288
|
-
}/[...${paramName}]
|
|
288
|
+
}/[...${paramName}]`,
|
|
289
289
|
);
|
|
290
290
|
try {
|
|
291
291
|
if (getStaticPaths) {
|
|
@@ -339,8 +339,8 @@ async function buildStaticPages() {
|
|
|
339
339
|
...(await collectPages(
|
|
340
340
|
dynamicPath,
|
|
341
341
|
[...segments, ...validSegmentsToAdd], // Use the filtered version
|
|
342
|
-
{ ...params, ...paramsToAdd }
|
|
343
|
-
))
|
|
342
|
+
{ ...params, ...paramsToAdd },
|
|
343
|
+
)),
|
|
344
344
|
);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
@@ -355,8 +355,8 @@ async function buildStaticPages() {
|
|
|
355
355
|
segments,
|
|
356
356
|
params,
|
|
357
357
|
[...dynamicStructure, paramName],
|
|
358
|
-
true
|
|
359
|
-
))
|
|
358
|
+
true,
|
|
359
|
+
)),
|
|
360
360
|
);
|
|
361
361
|
}
|
|
362
362
|
} else if (entry.name.startsWith("[[") && entry.name.endsWith("]]")) {
|
|
@@ -370,7 +370,7 @@ async function buildStaticPages() {
|
|
|
370
370
|
true,
|
|
371
371
|
true,
|
|
372
372
|
undefined,
|
|
373
|
-
segments.length
|
|
373
|
+
segments.length,
|
|
374
374
|
);
|
|
375
375
|
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
376
376
|
segments,
|
|
@@ -380,7 +380,7 @@ async function buildStaticPages() {
|
|
|
380
380
|
true,
|
|
381
381
|
true,
|
|
382
382
|
undefined,
|
|
383
|
-
segments.length
|
|
383
|
+
segments.length,
|
|
384
384
|
);
|
|
385
385
|
|
|
386
386
|
let dynamic, getStaticPaths;
|
|
@@ -395,7 +395,7 @@ async function buildStaticPages() {
|
|
|
395
395
|
console.log(
|
|
396
396
|
`Found optional dynamic route: ${
|
|
397
397
|
segments.join("/") ?? ""
|
|
398
|
-
}/[[${paramName}]]
|
|
398
|
+
}/[[${paramName}]]`,
|
|
399
399
|
);
|
|
400
400
|
try {
|
|
401
401
|
if (getStaticPaths) {
|
|
@@ -438,7 +438,7 @@ async function buildStaticPages() {
|
|
|
438
438
|
// Check to the right
|
|
439
439
|
const remaining = flatSegments.slice(index + 1);
|
|
440
440
|
return remaining.some(
|
|
441
|
-
(s) => s !== undefined && s !== null && s !== ""
|
|
441
|
+
(s) => s !== undefined && s !== null && s !== "",
|
|
442
442
|
);
|
|
443
443
|
});
|
|
444
444
|
|
|
@@ -448,7 +448,7 @@ async function buildStaticPages() {
|
|
|
448
448
|
|
|
449
449
|
// 🛡️ 3. URL CLEANING
|
|
450
450
|
const validSegmentsToAdd = flatSegments.filter(
|
|
451
|
-
(s) => s !== undefined && s !== null && s !== ""
|
|
451
|
+
(s) => s !== undefined && s !== null && s !== "",
|
|
452
452
|
);
|
|
453
453
|
|
|
454
454
|
// 🛡️ 4. PARAMS PREPARATION
|
|
@@ -462,8 +462,8 @@ async function buildStaticPages() {
|
|
|
462
462
|
...(await collectPages(
|
|
463
463
|
dynamicPath,
|
|
464
464
|
[...segments, ...validSegmentsToAdd],
|
|
465
|
-
{ ...params, ...paramsToAdd }
|
|
466
|
-
))
|
|
465
|
+
{ ...params, ...paramsToAdd },
|
|
466
|
+
)),
|
|
467
467
|
);
|
|
468
468
|
}
|
|
469
469
|
}
|
|
@@ -478,8 +478,8 @@ async function buildStaticPages() {
|
|
|
478
478
|
segments,
|
|
479
479
|
params,
|
|
480
480
|
[...dynamicStructure, paramName],
|
|
481
|
-
true
|
|
482
|
-
))
|
|
481
|
+
true,
|
|
482
|
+
)),
|
|
483
483
|
);
|
|
484
484
|
}
|
|
485
485
|
} else if (entry.name.startsWith("[") && entry.name.endsWith("]")) {
|
|
@@ -493,7 +493,7 @@ async function buildStaticPages() {
|
|
|
493
493
|
true,
|
|
494
494
|
true,
|
|
495
495
|
undefined,
|
|
496
|
-
segments.length
|
|
496
|
+
segments.length,
|
|
497
497
|
);
|
|
498
498
|
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
499
499
|
segments,
|
|
@@ -503,7 +503,7 @@ async function buildStaticPages() {
|
|
|
503
503
|
true,
|
|
504
504
|
true,
|
|
505
505
|
undefined,
|
|
506
|
-
segments.length
|
|
506
|
+
segments.length,
|
|
507
507
|
);
|
|
508
508
|
let dynamic;
|
|
509
509
|
let getStaticPaths;
|
|
@@ -516,7 +516,7 @@ async function buildStaticPages() {
|
|
|
516
516
|
pagePath && path.dirname(pagePath) === dynamicPath;
|
|
517
517
|
if (isLocalPage && !dynamic?.()) {
|
|
518
518
|
console.log(
|
|
519
|
-
`Found dynamic route: ${segments.join("/") ?? ""}/[${paramName}]
|
|
519
|
+
`Found dynamic route: ${segments.join("/") ?? ""}/[${paramName}]`,
|
|
520
520
|
);
|
|
521
521
|
try {
|
|
522
522
|
if (getStaticPaths) {
|
|
@@ -567,8 +567,8 @@ async function buildStaticPages() {
|
|
|
567
567
|
...(await collectPages(
|
|
568
568
|
dynamicPath,
|
|
569
569
|
[...segments, ...validSegmentsToAdd], // Use the filtered version
|
|
570
|
-
{ ...params, ...paramsToAdd }
|
|
571
|
-
))
|
|
570
|
+
{ ...params, ...paramsToAdd },
|
|
571
|
+
)),
|
|
572
572
|
);
|
|
573
573
|
}
|
|
574
574
|
}
|
|
@@ -582,8 +582,8 @@ async function buildStaticPages() {
|
|
|
582
582
|
segments,
|
|
583
583
|
params,
|
|
584
584
|
[...dynamicStructure, paramName],
|
|
585
|
-
true
|
|
586
|
-
))
|
|
585
|
+
true,
|
|
586
|
+
)),
|
|
587
587
|
);
|
|
588
588
|
}
|
|
589
589
|
} else if (!entry.name.startsWith("@")) {
|
|
@@ -597,7 +597,7 @@ async function buildStaticPages() {
|
|
|
597
597
|
true,
|
|
598
598
|
true,
|
|
599
599
|
undefined,
|
|
600
|
-
segments.length
|
|
600
|
+
segments.length,
|
|
601
601
|
);
|
|
602
602
|
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
603
603
|
segments,
|
|
@@ -607,7 +607,7 @@ async function buildStaticPages() {
|
|
|
607
607
|
true,
|
|
608
608
|
true,
|
|
609
609
|
undefined,
|
|
610
|
-
segments.length
|
|
610
|
+
segments.length,
|
|
611
611
|
);
|
|
612
612
|
let dynamic;
|
|
613
613
|
let getStaticPaths;
|
|
@@ -669,8 +669,8 @@ async function buildStaticPages() {
|
|
|
669
669
|
...(await collectPages(
|
|
670
670
|
dynamicPath,
|
|
671
671
|
[...segments, ...validSegmentsToAdd, entry.name], // Use the filtered version
|
|
672
|
-
{ ...params, ...paramsToAdd }
|
|
673
|
-
))
|
|
672
|
+
{ ...params, ...paramsToAdd },
|
|
673
|
+
)),
|
|
674
674
|
);
|
|
675
675
|
}
|
|
676
676
|
}
|
|
@@ -684,8 +684,8 @@ async function buildStaticPages() {
|
|
|
684
684
|
segments,
|
|
685
685
|
params,
|
|
686
686
|
[...dynamicStructure, { STATIC_PARAM_NAME: entry.name }],
|
|
687
|
-
true
|
|
688
|
-
))
|
|
687
|
+
true,
|
|
688
|
+
)),
|
|
689
689
|
);
|
|
690
690
|
}
|
|
691
691
|
} else {
|
|
@@ -695,8 +695,8 @@ async function buildStaticPages() {
|
|
|
695
695
|
[...segments, entry.name],
|
|
696
696
|
params,
|
|
697
697
|
dynamicStructure,
|
|
698
|
-
false
|
|
699
|
-
))
|
|
698
|
+
false,
|
|
699
|
+
)),
|
|
700
700
|
);
|
|
701
701
|
}
|
|
702
702
|
}
|
|
@@ -712,7 +712,7 @@ async function buildStaticPages() {
|
|
|
712
712
|
true,
|
|
713
713
|
undefined,
|
|
714
714
|
segments.length,
|
|
715
|
-
params
|
|
715
|
+
params,
|
|
716
716
|
);
|
|
717
717
|
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
718
718
|
segments,
|
|
@@ -722,7 +722,7 @@ async function buildStaticPages() {
|
|
|
722
722
|
true,
|
|
723
723
|
true,
|
|
724
724
|
undefined,
|
|
725
|
-
segments.length
|
|
725
|
+
segments.length,
|
|
726
726
|
);
|
|
727
727
|
let dynamic;
|
|
728
728
|
if (pageFunctionsPath) {
|
|
@@ -746,105 +746,7 @@ async function buildStaticPages() {
|
|
|
746
746
|
|
|
747
747
|
for (const { path: folderPath, segments, params } of pages) {
|
|
748
748
|
try {
|
|
749
|
-
const
|
|
750
|
-
segments,
|
|
751
|
-
{},
|
|
752
|
-
folderPath,
|
|
753
|
-
"page",
|
|
754
|
-
true,
|
|
755
|
-
true,
|
|
756
|
-
undefined,
|
|
757
|
-
segments.length
|
|
758
|
-
);
|
|
759
|
-
const pageModule = await importModule(pagePath);
|
|
760
|
-
const Page = pageModule.default ?? pageModule;
|
|
761
|
-
// Set displayName for better serialization
|
|
762
|
-
// if (!Page.displayName) Page.displayName = "Page";
|
|
763
|
-
|
|
764
|
-
let props = { params /* searchParams: {}*/ };
|
|
765
|
-
|
|
766
|
-
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
767
|
-
segments,
|
|
768
|
-
{},
|
|
769
|
-
folderPath,
|
|
770
|
-
"page_functions",
|
|
771
|
-
true,
|
|
772
|
-
true,
|
|
773
|
-
undefined,
|
|
774
|
-
segments.length
|
|
775
|
-
);
|
|
776
|
-
|
|
777
|
-
let pageFunctionsProps;
|
|
778
|
-
let revalidate;
|
|
779
|
-
|
|
780
|
-
if (pageFunctionsPath) {
|
|
781
|
-
const pageFunctionsModule = await importModule(pageFunctionsPath);
|
|
782
|
-
const getProps = pageFunctionsModule.getProps;
|
|
783
|
-
revalidate = pageFunctionsModule.revalidate;
|
|
784
|
-
pageFunctionsProps = await getProps?.(params);
|
|
785
|
-
props = { ...props, ...(pageFunctionsProps?.page ?? {}) };
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
let jsx = React.createElement(Page, props);
|
|
789
|
-
jsx = { ...jsx, __modulePath: pagePath };
|
|
790
|
-
|
|
791
|
-
const noLayoutPath = path.join(folderPath, "no_layout");
|
|
792
|
-
if (!existsSync(noLayoutPath)) {
|
|
793
|
-
const layouts = getFilePathAndDynamicParams(
|
|
794
|
-
segments,
|
|
795
|
-
{},
|
|
796
|
-
srcFolder,
|
|
797
|
-
"layout",
|
|
798
|
-
true,
|
|
799
|
-
false,
|
|
800
|
-
undefined,
|
|
801
|
-
0,
|
|
802
|
-
{},
|
|
803
|
-
true
|
|
804
|
-
);
|
|
805
|
-
|
|
806
|
-
if (layouts && Array.isArray(layouts)) {
|
|
807
|
-
let index = 0;
|
|
808
|
-
for (const [layoutPath, dParams, slots] of layouts.reverse()) {
|
|
809
|
-
const layoutModule = await importModule(layoutPath);
|
|
810
|
-
const Layout = layoutModule.default ?? layoutModule;
|
|
811
|
-
// if (!Layout.displayName) Layout.displayName = "Layout";
|
|
812
|
-
const updatedSlots = {};
|
|
813
|
-
for (const [slotName, slotElement] of Object.entries(slots)) {
|
|
814
|
-
const alreadyFoundPath = slotElement.props?.__modulePath;
|
|
815
|
-
|
|
816
|
-
updatedSlots[slotName] = {
|
|
817
|
-
...slotElement,
|
|
818
|
-
__modulePath: alreadyFoundPath ?? null,
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
let props = {
|
|
822
|
-
params: dParams,
|
|
823
|
-
/*searchParams: {},*/ ...updatedSlots,
|
|
824
|
-
};
|
|
825
|
-
if (index === layouts.length - 1) {
|
|
826
|
-
props = { ...props, ...(pageFunctionsProps?.layout ?? {}) };
|
|
827
|
-
}
|
|
828
|
-
jsx = React.createElement(Layout, props, jsx);
|
|
829
|
-
jsx = { ...jsx, __modulePath: layoutPath };
|
|
830
|
-
const layoutFolderPath = path.dirname(layoutPath);
|
|
831
|
-
if (
|
|
832
|
-
getFilePathAndDynamicParams(
|
|
833
|
-
[],
|
|
834
|
-
{},
|
|
835
|
-
layoutFolderPath,
|
|
836
|
-
"reset_layout",
|
|
837
|
-
false
|
|
838
|
-
)[0]
|
|
839
|
-
) {
|
|
840
|
-
break;
|
|
841
|
-
}
|
|
842
|
-
index++;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
const segmentsJoin = segments.join("/");
|
|
847
|
-
const reqPath = segments.length ? "/" + segmentsJoin + "/" : "/";
|
|
749
|
+
const reqPath = segments.length ? "/" + segments.join("/") + "/" : "/";
|
|
848
750
|
// ====================================================================
|
|
849
751
|
// 1. MOCK RES: Fulfilling ResponseProxy interface
|
|
850
752
|
// ====================================================================
|
|
@@ -895,7 +797,7 @@ async function buildStaticPages() {
|
|
|
895
797
|
|
|
896
798
|
// Log warning because a redirect in SSG is usually problematic
|
|
897
799
|
console.warn(
|
|
898
|
-
`⚠️ [SSG] Redirect detected in ${reqPath} -> ${url} (${status})
|
|
800
|
+
`⚠️ [SSG] Redirect detected in ${reqPath} -> ${url} (${status})`,
|
|
899
801
|
);
|
|
900
802
|
},
|
|
901
803
|
};
|
|
@@ -937,7 +839,103 @@ async function buildStaticPages() {
|
|
|
937
839
|
res: mockRes,
|
|
938
840
|
};
|
|
939
841
|
|
|
940
|
-
|
|
842
|
+
let revalidate;
|
|
843
|
+
const jsx = await requestStorage.run(mockContext, async () => {
|
|
844
|
+
const [pagePath] = getFilePathAndDynamicParams(
|
|
845
|
+
segments,
|
|
846
|
+
{},
|
|
847
|
+
folderPath,
|
|
848
|
+
"page",
|
|
849
|
+
true,
|
|
850
|
+
true,
|
|
851
|
+
undefined,
|
|
852
|
+
segments.length,
|
|
853
|
+
);
|
|
854
|
+
const pageModule = await importModule(pagePath);
|
|
855
|
+
const Page = pageModule.default ?? pageModule;
|
|
856
|
+
// Set displayName for better serialization
|
|
857
|
+
// if (!Page.displayName) Page.displayName = "Page";
|
|
858
|
+
|
|
859
|
+
let props = { params /* searchParams: {}*/ };
|
|
860
|
+
|
|
861
|
+
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
862
|
+
segments,
|
|
863
|
+
{},
|
|
864
|
+
folderPath,
|
|
865
|
+
"page_functions",
|
|
866
|
+
true,
|
|
867
|
+
true,
|
|
868
|
+
undefined,
|
|
869
|
+
segments.length,
|
|
870
|
+
);
|
|
871
|
+
|
|
872
|
+
let pageFunctionsProps;
|
|
873
|
+
|
|
874
|
+
if (pageFunctionsPath) {
|
|
875
|
+
const pageFunctionsModule = await importModule(pageFunctionsPath);
|
|
876
|
+
const getProps = pageFunctionsModule.getProps;
|
|
877
|
+
revalidate = pageFunctionsModule.revalidate;
|
|
878
|
+
pageFunctionsProps = await getProps?.(params);
|
|
879
|
+
props = { ...props, ...(pageFunctionsProps?.page ?? {}) };
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
let jsx = React.createElement(Page, props);
|
|
883
|
+
jsx = { ...jsx, __modulePath: pagePath };
|
|
884
|
+
|
|
885
|
+
const noLayoutPath = path.join(folderPath, "no_layout");
|
|
886
|
+
if (!existsSync(noLayoutPath)) {
|
|
887
|
+
const layouts = getFilePathAndDynamicParams(
|
|
888
|
+
segments,
|
|
889
|
+
{},
|
|
890
|
+
srcFolder,
|
|
891
|
+
"layout",
|
|
892
|
+
true,
|
|
893
|
+
false,
|
|
894
|
+
undefined,
|
|
895
|
+
0,
|
|
896
|
+
{},
|
|
897
|
+
true,
|
|
898
|
+
);
|
|
899
|
+
|
|
900
|
+
if (layouts && Array.isArray(layouts)) {
|
|
901
|
+
let index = 0;
|
|
902
|
+
for (const [layoutPath, dParams, slots] of layouts.reverse()) {
|
|
903
|
+
const layoutModule = await importModule(layoutPath);
|
|
904
|
+
const Layout = layoutModule.default ?? layoutModule;
|
|
905
|
+
const layoutFolderPath = path.dirname(layoutPath);
|
|
906
|
+
const resetLayoutPath = getFilePathAndDynamicParams(
|
|
907
|
+
[],
|
|
908
|
+
{},
|
|
909
|
+
layoutFolderPath,
|
|
910
|
+
"reset_layout",
|
|
911
|
+
false,
|
|
912
|
+
)[0];
|
|
913
|
+
const updatedSlots = {};
|
|
914
|
+
for (const [slotName, slotElement] of Object.entries(slots)) {
|
|
915
|
+
const alreadyFoundPath = slotElement.props?.__modulePath;
|
|
916
|
+
|
|
917
|
+
updatedSlots[slotName] = {
|
|
918
|
+
...slotElement,
|
|
919
|
+
__modulePath: alreadyFoundPath ?? null,
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
let props = {
|
|
923
|
+
params: dParams,
|
|
924
|
+
/*searchParams: {},*/ ...updatedSlots,
|
|
925
|
+
};
|
|
926
|
+
if (index === layouts.length - 1 || resetLayoutPath) {
|
|
927
|
+
props = { ...props, ...(pageFunctionsProps?.layout ?? {}) };
|
|
928
|
+
}
|
|
929
|
+
jsx = React.createElement(Layout, props, jsx);
|
|
930
|
+
jsx = { ...jsx, __modulePath: layoutPath };
|
|
931
|
+
if (resetLayoutPath) {
|
|
932
|
+
break;
|
|
933
|
+
}
|
|
934
|
+
index++;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
941
939
|
return await asyncRenderJSXToClientJSX(jsx);
|
|
942
940
|
});
|
|
943
941
|
|
|
@@ -946,8 +944,8 @@ async function buildStaticPages() {
|
|
|
946
944
|
// Will behave as pure SSR at runtime.
|
|
947
945
|
console.log(
|
|
948
946
|
`Skipping static generation for ${segments.join(
|
|
949
|
-
"/"
|
|
950
|
-
)} due to dynamic usage
|
|
947
|
+
"/",
|
|
948
|
+
)} due to dynamic usage.`,
|
|
951
949
|
);
|
|
952
950
|
continue;
|
|
953
951
|
}
|
|
@@ -1004,7 +1002,7 @@ async function buildStaticPage(reqPath, isDynamic = null) {
|
|
|
1004
1002
|
(entry) =>
|
|
1005
1003
|
entry.isDirectory() &&
|
|
1006
1004
|
((entry.name.startsWith("[") && entry.name.endsWith("]")) ||
|
|
1007
|
-
(entry.name.startsWith("[[") && entry.name.endsWith("]]")))
|
|
1005
|
+
(entry.name.startsWith("[[") && entry.name.endsWith("]]"))),
|
|
1008
1006
|
);
|
|
1009
1007
|
|
|
1010
1008
|
if (dynamicEntry) {
|
|
@@ -1022,108 +1020,6 @@ async function buildStaticPage(reqPath, isDynamic = null) {
|
|
|
1022
1020
|
throw new Error(`No matching route found for ${reqPath}`);
|
|
1023
1021
|
}
|
|
1024
1022
|
}
|
|
1025
|
-
|
|
1026
|
-
const [pagePath, dParams] = getFilePathAndDynamicParams(
|
|
1027
|
-
segments,
|
|
1028
|
-
{},
|
|
1029
|
-
folderPath,
|
|
1030
|
-
"page",
|
|
1031
|
-
true,
|
|
1032
|
-
true,
|
|
1033
|
-
undefined,
|
|
1034
|
-
segments.length,
|
|
1035
|
-
dynamicParams
|
|
1036
|
-
);
|
|
1037
|
-
if (!pagePath) throw new Error(`No page found for ${reqPath}`);
|
|
1038
|
-
|
|
1039
|
-
const pageModule = await importModule(pagePath);
|
|
1040
|
-
const Page = pageModule.default ?? pageModule;
|
|
1041
|
-
|
|
1042
|
-
let props = { params: dParams /*searchParams: {}*/ };
|
|
1043
|
-
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
1044
|
-
segments,
|
|
1045
|
-
{},
|
|
1046
|
-
folderPath,
|
|
1047
|
-
"page_functions",
|
|
1048
|
-
true,
|
|
1049
|
-
true,
|
|
1050
|
-
undefined,
|
|
1051
|
-
segments.length
|
|
1052
|
-
);
|
|
1053
|
-
|
|
1054
|
-
let pageFunctionsProps;
|
|
1055
|
-
let revalidate;
|
|
1056
|
-
if (pageFunctionsPath) {
|
|
1057
|
-
const pageFunctionsModule = await importModule(pageFunctionsPath);
|
|
1058
|
-
const getProps = pageFunctionsModule.getProps;
|
|
1059
|
-
if (isDynamic && (isDynamic.value = pageFunctionsModule.dynamic?.()))
|
|
1060
|
-
return;
|
|
1061
|
-
revalidate = pageFunctionsModule.revalidate;
|
|
1062
|
-
pageFunctionsProps = await getProps?.(dParams);
|
|
1063
|
-
props = { ...props, ...(pageFunctionsProps?.page ?? {}) };
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
let jsx = React.createElement(Page, props);
|
|
1067
|
-
jsx = { ...jsx, __modulePath: pagePath };
|
|
1068
|
-
|
|
1069
|
-
const noLayoutPath = path.join(folderPath, "no_layout");
|
|
1070
|
-
if (!existsSync(noLayoutPath)) {
|
|
1071
|
-
const layouts = getFilePathAndDynamicParams(
|
|
1072
|
-
segments,
|
|
1073
|
-
{},
|
|
1074
|
-
srcFolder,
|
|
1075
|
-
"layout",
|
|
1076
|
-
true,
|
|
1077
|
-
false,
|
|
1078
|
-
undefined,
|
|
1079
|
-
0,
|
|
1080
|
-
{},
|
|
1081
|
-
true
|
|
1082
|
-
);
|
|
1083
|
-
if (layouts && Array.isArray(layouts)) {
|
|
1084
|
-
let index = 0;
|
|
1085
|
-
for (const [layoutPath, dParams, slots] of layouts.reverse()) {
|
|
1086
|
-
const layoutModule = await importModule(layoutPath);
|
|
1087
|
-
const Layout = layoutModule.default ?? layoutModule;
|
|
1088
|
-
const updatedSlots = {};
|
|
1089
|
-
for (const [slotName, slotElement] of Object.entries(slots)) {
|
|
1090
|
-
const alreadyFoundPath = slotElement.props?.__modulePath;
|
|
1091
|
-
|
|
1092
|
-
updatedSlots[slotName] = {
|
|
1093
|
-
...slotElement,
|
|
1094
|
-
__modulePath: alreadyFoundPath ?? null,
|
|
1095
|
-
};
|
|
1096
|
-
}
|
|
1097
|
-
let layoutProps = {
|
|
1098
|
-
params: dParams,
|
|
1099
|
-
// searchParams: {},
|
|
1100
|
-
...updatedSlots,
|
|
1101
|
-
};
|
|
1102
|
-
if (index === layouts.length - 1) {
|
|
1103
|
-
layoutProps = {
|
|
1104
|
-
...layoutProps,
|
|
1105
|
-
...(pageFunctionsProps?.layout ?? {}),
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
jsx = React.createElement(Layout, layoutProps, jsx);
|
|
1109
|
-
jsx = { ...jsx, __modulePath: layoutPath };
|
|
1110
|
-
const layoutFolderPath = path.dirname(layoutPath);
|
|
1111
|
-
if (
|
|
1112
|
-
getFilePathAndDynamicParams(
|
|
1113
|
-
[],
|
|
1114
|
-
{},
|
|
1115
|
-
layoutFolderPath,
|
|
1116
|
-
"reset_layout",
|
|
1117
|
-
false
|
|
1118
|
-
)[0]
|
|
1119
|
-
) {
|
|
1120
|
-
break;
|
|
1121
|
-
}
|
|
1122
|
-
index++;
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
1023
|
// ====================================================================
|
|
1128
1024
|
// 1. MOCK RES: Fulfilling the ResponseProxy interface
|
|
1129
1025
|
// ====================================================================
|
|
@@ -1174,7 +1070,7 @@ async function buildStaticPage(reqPath, isDynamic = null) {
|
|
|
1174
1070
|
|
|
1175
1071
|
// We log a warning because a redirect in SSG is usually problematic
|
|
1176
1072
|
console.warn(
|
|
1177
|
-
`⚠️ [SSG] Redirect detected in ${reqPath} -> ${url} (${status})
|
|
1073
|
+
`⚠️ [SSG] Redirect detected in ${reqPath} -> ${url} (${status})`,
|
|
1178
1074
|
);
|
|
1179
1075
|
},
|
|
1180
1076
|
};
|
|
@@ -1216,7 +1112,107 @@ async function buildStaticPage(reqPath, isDynamic = null) {
|
|
|
1216
1112
|
res: mockRes,
|
|
1217
1113
|
};
|
|
1218
1114
|
|
|
1219
|
-
|
|
1115
|
+
let revalidate;
|
|
1116
|
+
const jsx = await requestStorage.run(mockContext, async () => {
|
|
1117
|
+
const [pagePath, dParams] = getFilePathAndDynamicParams(
|
|
1118
|
+
segments,
|
|
1119
|
+
{},
|
|
1120
|
+
folderPath,
|
|
1121
|
+
"page",
|
|
1122
|
+
true,
|
|
1123
|
+
true,
|
|
1124
|
+
undefined,
|
|
1125
|
+
segments.length,
|
|
1126
|
+
dynamicParams,
|
|
1127
|
+
);
|
|
1128
|
+
if (!pagePath) throw new Error(`No page found for ${reqPath}`);
|
|
1129
|
+
|
|
1130
|
+
const pageModule = await importModule(pagePath);
|
|
1131
|
+
const Page = pageModule.default ?? pageModule;
|
|
1132
|
+
|
|
1133
|
+
let props = { params: dParams /*searchParams: {}*/ };
|
|
1134
|
+
const [pageFunctionsPath] = getFilePathAndDynamicParams(
|
|
1135
|
+
segments,
|
|
1136
|
+
{},
|
|
1137
|
+
folderPath,
|
|
1138
|
+
"page_functions",
|
|
1139
|
+
true,
|
|
1140
|
+
true,
|
|
1141
|
+
undefined,
|
|
1142
|
+
segments.length,
|
|
1143
|
+
);
|
|
1144
|
+
|
|
1145
|
+
let pageFunctionsProps;
|
|
1146
|
+
if (pageFunctionsPath) {
|
|
1147
|
+
const pageFunctionsModule = await importModule(pageFunctionsPath);
|
|
1148
|
+
const getProps = pageFunctionsModule.getProps;
|
|
1149
|
+
if (isDynamic && (isDynamic.value = pageFunctionsModule.dynamic?.()))
|
|
1150
|
+
return;
|
|
1151
|
+
revalidate = pageFunctionsModule.revalidate;
|
|
1152
|
+
pageFunctionsProps = await getProps?.(dParams);
|
|
1153
|
+
props = { ...props, ...(pageFunctionsProps?.page ?? {}) };
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
let jsx = React.createElement(Page, props);
|
|
1157
|
+
jsx = { ...jsx, __modulePath: pagePath };
|
|
1158
|
+
|
|
1159
|
+
const noLayoutPath = path.join(folderPath, "no_layout");
|
|
1160
|
+
if (!existsSync(noLayoutPath)) {
|
|
1161
|
+
const layouts = getFilePathAndDynamicParams(
|
|
1162
|
+
segments,
|
|
1163
|
+
{},
|
|
1164
|
+
srcFolder,
|
|
1165
|
+
"layout",
|
|
1166
|
+
true,
|
|
1167
|
+
false,
|
|
1168
|
+
undefined,
|
|
1169
|
+
0,
|
|
1170
|
+
{},
|
|
1171
|
+
true,
|
|
1172
|
+
);
|
|
1173
|
+
if (layouts && Array.isArray(layouts)) {
|
|
1174
|
+
let index = 0;
|
|
1175
|
+
for (const [layoutPath, dParams, slots] of layouts.reverse()) {
|
|
1176
|
+
const layoutModule = await importModule(layoutPath);
|
|
1177
|
+
const Layout = layoutModule.default ?? layoutModule;
|
|
1178
|
+
const layoutFolderPath = path.dirname(layoutPath);
|
|
1179
|
+
const resetLayoutPath = getFilePathAndDynamicParams(
|
|
1180
|
+
[],
|
|
1181
|
+
{},
|
|
1182
|
+
layoutFolderPath,
|
|
1183
|
+
"reset_layout",
|
|
1184
|
+
false,
|
|
1185
|
+
)[0];
|
|
1186
|
+
const updatedSlots = {};
|
|
1187
|
+
for (const [slotName, slotElement] of Object.entries(slots)) {
|
|
1188
|
+
const alreadyFoundPath = slotElement.props?.__modulePath;
|
|
1189
|
+
|
|
1190
|
+
updatedSlots[slotName] = {
|
|
1191
|
+
...slotElement,
|
|
1192
|
+
__modulePath: alreadyFoundPath ?? null,
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
let layoutProps = {
|
|
1196
|
+
params: dParams,
|
|
1197
|
+
// searchParams: {},
|
|
1198
|
+
...updatedSlots,
|
|
1199
|
+
};
|
|
1200
|
+
if (index === layouts.length - 1 || resetLayoutPath) {
|
|
1201
|
+
layoutProps = {
|
|
1202
|
+
...layoutProps,
|
|
1203
|
+
...(pageFunctionsProps?.layout ?? {}),
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
jsx = React.createElement(Layout, layoutProps, jsx);
|
|
1207
|
+
jsx = { ...jsx, __modulePath: layoutPath };
|
|
1208
|
+
if (resetLayoutPath) {
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
index++;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1220
1216
|
return await asyncRenderJSXToClientJSX(jsx);
|
|
1221
1217
|
});
|
|
1222
1218
|
|
|
@@ -1225,8 +1221,8 @@ async function buildStaticPage(reqPath, isDynamic = null) {
|
|
|
1225
1221
|
// It will behave as pure SSR at runtime.
|
|
1226
1222
|
console.log(
|
|
1227
1223
|
`Skipping static generation for ${segments.join(
|
|
1228
|
-
"/"
|
|
1229
|
-
)} due to dynamic usage
|
|
1224
|
+
"/",
|
|
1225
|
+
)} due to dynamic usage.`,
|
|
1230
1226
|
);
|
|
1231
1227
|
if (isDynamic) {
|
|
1232
1228
|
isDynamic.value = true;
|
|
@@ -1311,15 +1307,15 @@ function serializeReactElement(element) {
|
|
|
1311
1307
|
modulePath: isPackage
|
|
1312
1308
|
? modulePath
|
|
1313
1309
|
: modulePath
|
|
1314
|
-
|
|
1315
|
-
|
|
1310
|
+
? path.relative(process.cwd(), modulePath).split(path.sep).join("/")
|
|
1311
|
+
: null,
|
|
1316
1312
|
props: {
|
|
1317
1313
|
...filterProps(element.props),
|
|
1318
1314
|
children: Array.isArray(element.props.children)
|
|
1319
1315
|
? element.props.children.map((child) => serializeReactElement(child))
|
|
1320
1316
|
: element.props.children
|
|
1321
|
-
|
|
1322
|
-
|
|
1317
|
+
? serializeReactElement(element.props.children)
|
|
1318
|
+
: undefined,
|
|
1323
1319
|
},
|
|
1324
1320
|
};
|
|
1325
1321
|
}
|