dinou 4.0.4 → 4.0.6

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 CHANGED
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
 
8
+ ## [4.0.6]
9
+
10
+ ### Fixed
11
+
12
+ - Execute page_functions on not_found page too in getJSX.
13
+
14
+ ## [4.0.5]
15
+
16
+ ### Fixed
17
+
18
+ - Pass props to RootLayout in BuildStaticPages.
19
+
8
20
  ## [4.0.4]
9
21
 
10
22
  ### Fixed
@@ -902,7 +902,14 @@ async function buildStaticPages() {
902
902
  for (const [layoutPath, dParams, slots] of layouts.reverse()) {
903
903
  const layoutModule = await importModule(layoutPath);
904
904
  const Layout = layoutModule.default ?? layoutModule;
905
- // if (!Layout.displayName) Layout.displayName = "Layout";
905
+ const layoutFolderPath = path.dirname(layoutPath);
906
+ const resetLayoutPath = getFilePathAndDynamicParams(
907
+ [],
908
+ {},
909
+ layoutFolderPath,
910
+ "reset_layout",
911
+ false,
912
+ )[0];
906
913
  const updatedSlots = {};
907
914
  for (const [slotName, slotElement] of Object.entries(slots)) {
908
915
  const alreadyFoundPath = slotElement.props?.__modulePath;
@@ -916,21 +923,12 @@ async function buildStaticPages() {
916
923
  params: dParams,
917
924
  /*searchParams: {},*/ ...updatedSlots,
918
925
  };
919
- if (index === layouts.length - 1) {
926
+ if (index === layouts.length - 1 || resetLayoutPath) {
920
927
  props = { ...props, ...(pageFunctionsProps?.layout ?? {}) };
921
928
  }
922
929
  jsx = React.createElement(Layout, props, jsx);
923
930
  jsx = { ...jsx, __modulePath: layoutPath };
924
- const layoutFolderPath = path.dirname(layoutPath);
925
- if (
926
- getFilePathAndDynamicParams(
927
- [],
928
- {},
929
- layoutFolderPath,
930
- "reset_layout",
931
- false,
932
- )[0]
933
- ) {
931
+ if (resetLayoutPath) {
934
932
  break;
935
933
  }
936
934
  index++;
@@ -1177,6 +1175,14 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1177
1175
  for (const [layoutPath, dParams, slots] of layouts.reverse()) {
1178
1176
  const layoutModule = await importModule(layoutPath);
1179
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];
1180
1186
  const updatedSlots = {};
1181
1187
  for (const [slotName, slotElement] of Object.entries(slots)) {
1182
1188
  const alreadyFoundPath = slotElement.props?.__modulePath;
@@ -1191,7 +1197,7 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1191
1197
  // searchParams: {},
1192
1198
  ...updatedSlots,
1193
1199
  };
1194
- if (index === layouts.length - 1) {
1200
+ if (index === layouts.length - 1 || resetLayoutPath) {
1195
1201
  layoutProps = {
1196
1202
  ...layoutProps,
1197
1203
  ...(pageFunctionsProps?.layout ?? {}),
@@ -1199,16 +1205,7 @@ async function buildStaticPage(reqPath, isDynamic = null) {
1199
1205
  }
1200
1206
  jsx = React.createElement(Layout, layoutProps, jsx);
1201
1207
  jsx = { ...jsx, __modulePath: layoutPath };
1202
- const layoutFolderPath = path.dirname(layoutPath);
1203
- if (
1204
- getFilePathAndDynamicParams(
1205
- [],
1206
- {},
1207
- layoutFolderPath,
1208
- "reset_layout",
1209
- false,
1210
- )[0]
1211
- ) {
1208
+ if (resetLayoutPath) {
1212
1209
  break;
1213
1210
  }
1214
1211
  index++;
@@ -11,7 +11,7 @@ async function getJSX(
11
11
  reqPath,
12
12
  query,
13
13
  isNotFound = null,
14
- isDevelopment = false
14
+ isDevelopment = false,
15
15
  ) {
16
16
  const srcFolder = path.resolve(process.cwd(), "src");
17
17
  const reqSegments = reqPath.split("/").filter(Boolean);
@@ -43,7 +43,7 @@ async function getJSX(
43
43
  const [filePath, dParams] = getFilePathAndDynamicParams(
44
44
  reqSegments,
45
45
  query,
46
- srcFolder
46
+ srcFolder,
47
47
  );
48
48
  pagePath = filePath;
49
49
  dynamicParams = dParams ?? {};
@@ -60,26 +60,43 @@ async function getJSX(
60
60
  srcFolder,
61
61
  "not_found",
62
62
  true,
63
- false
63
+ false,
64
64
  );
65
65
  if (!notFoundPath) {
66
66
  jsx = React.createElement(
67
67
  "div",
68
68
  null,
69
- `Page not found: no "page" file found for "${reqPath}"`
69
+ `Page not found: no "page" file found for "${reqPath}"`,
70
70
  );
71
71
  } else {
72
72
  const pageModule = await importModule(notFoundPath);
73
73
  const Page = pageModule.default ?? pageModule;
74
- jsx = React.createElement(Page, {
74
+ let props = {
75
75
  params: dParams ?? {},
76
- // searchParams: query,
77
- });
78
-
76
+ };
79
77
  const notFoundDir = path.dirname(notFoundPath);
78
+
79
+ const [pageFunctionsPath] = getFilePathAndDynamicParams(
80
+ reqSegments,
81
+ query,
82
+ notFoundDir,
83
+ "page_functions",
84
+ true,
85
+ true,
86
+ undefined,
87
+ reqSegments.length,
88
+ );
89
+ if (pageFunctionsPath) {
90
+ const pageFunctionsModule = await importModule(pageFunctionsPath);
91
+ const getProps = pageFunctionsModule.getProps;
92
+ pageFunctionsProps = await getProps?.(dParams ?? {});
93
+ props = { ...props, ...(pageFunctionsProps?.page ?? {}) };
94
+ }
95
+
96
+ jsx = React.createElement(Page, props);
80
97
  const noLayoutNotFoundPath = path.join(
81
98
  notFoundDir,
82
- `no_layout_not_found`
99
+ `no_layout_not_found`,
83
100
  );
84
101
  if (existsSync(noLayoutNotFoundPath)) {
85
102
  return jsx;
@@ -104,7 +121,7 @@ async function getJSX(
104
121
  true,
105
122
  true,
106
123
  undefined,
107
- reqSegments.length
124
+ reqSegments.length,
108
125
  );
109
126
  if (pageFunctionsPath) {
110
127
  const pageFunctionsModule = await importModule(pageFunctionsPath);
@@ -122,7 +139,7 @@ async function getJSX(
122
139
  query,
123
140
  srcFolder,
124
141
  "no_layout",
125
- false
142
+ false,
126
143
  )[0]
127
144
  ) {
128
145
  return jsx;
@@ -138,7 +155,7 @@ async function getJSX(
138
155
  undefined,
139
156
  0,
140
157
  {},
141
- true
158
+ true,
142
159
  );
143
160
 
144
161
  if (layouts && Array.isArray(layouts)) {
@@ -151,7 +168,7 @@ async function getJSX(
151
168
  {},
152
169
  layoutFolderPath,
153
170
  "reset_layout",
154
- false
171
+ false,
155
172
  )[0];
156
173
  const Layout = layoutModule.default ?? layoutModule;
157
174
  const updatedSlots = {};
@@ -175,7 +192,7 @@ async function getJSX(
175
192
  true, // withExtension
176
193
  true, // finalDestination
177
194
  undefined, // lastFound
178
- reqSegments.length
195
+ reqSegments.length,
179
196
  );
180
197
 
181
198
  if (slotErrorPath) {
@@ -196,13 +213,13 @@ async function getJSX(
196
213
  });
197
214
  } else {
198
215
  console.warn(
199
- `[Dinou] Slot @${slotName} failed and does not have error.tsx`
216
+ `[Dinou] Slot @${slotName} failed and does not have error.tsx`,
200
217
  );
201
218
  updatedSlotElement = null;
202
219
  }
203
220
  } else {
204
221
  console.error(
205
- `[Dinou] Could not locate the path of the slot @${slotName}`
222
+ `[Dinou] Could not locate the path of the slot @${slotName}`,
206
223
  );
207
224
  updatedSlotElement = null;
208
225
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinou-ejected",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "main": "index.js",
5
5
  "private": true,
6
6
  "exports": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dinou",
3
- "version": "4.0.4",
4
- "description": "Modern Full-Stack React 19 framework with React Server Components, Server Functions, and Streaming SSR.",
3
+ "version": "4.0.6",
4
+ "description": "Full-Stack React 19 framework with React Server Components, Server Functions, and Streaming SSR.",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "dinou": "./cli.js"