@akanjs/next 0.0.149 → 0.0.150
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/bootCsr.d.ts +1 -1
- package/cjs/bootCsr.js +26 -16
- package/esm/bootCsr.js +26 -16
- package/package.json +1 -1
package/bootCsr.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const bootCsr: (context: Record<string, () => Promise<unknown
|
|
1
|
+
export declare const bootCsr: (context: Record<string, () => Promise<unknown>>) => Promise<void>;
|
package/cjs/bootCsr.js
CHANGED
|
@@ -38,15 +38,33 @@ var import_react = __toESM(require("react"));
|
|
|
38
38
|
var ReactDOM = __toESM(require("react-dom/client"));
|
|
39
39
|
var import_useCsrValues = require("./useCsrValues");
|
|
40
40
|
const supportLanguages = ["en", "ko"];
|
|
41
|
-
const bootCsr = async (context
|
|
41
|
+
const bootCsr = async (context) => {
|
|
42
|
+
window.document.body.style.overflow = "hidden";
|
|
43
|
+
const pathname = window.location.pathname;
|
|
44
|
+
if (pathname === "/404")
|
|
45
|
+
return;
|
|
42
46
|
const [, jwt] = await Promise.all([import_client.device.init({ supportLanguages }), import_client.storage.getItem("jwt")]);
|
|
47
|
+
if (!pathname.startsWith(`/${import_client.device.lang}`))
|
|
48
|
+
window.location.replace(`/${import_client.device.lang}${pathname}`);
|
|
43
49
|
if (jwt)
|
|
44
50
|
(0, import_client.initAuth)({ jwt });
|
|
45
51
|
import_common.Logger.verbose(`Set default language: ${import_client.device.lang}`);
|
|
52
|
+
const basePaths = process.env.basePaths?.split(",");
|
|
53
|
+
const currentBasePath = basePaths ? pathname.split("/")[2] : void 0;
|
|
54
|
+
if (currentBasePath && basePaths && !basePaths.includes(currentBasePath))
|
|
55
|
+
throw new Error(`Invalid path: ${pathname}`);
|
|
56
|
+
const baseLayoutPaths = ["/", "/:lang", ...currentBasePath ? [`/:lang/${currentBasePath}`] : []];
|
|
57
|
+
const otherBasePaths = basePaths?.filter((path) => path !== currentBasePath) ?? [];
|
|
46
58
|
const pages = {};
|
|
47
59
|
await Promise.all(
|
|
48
60
|
Object.entries(context).map(async ([key, value]) => {
|
|
49
|
-
|
|
61
|
+
if (basePaths) {
|
|
62
|
+
const pageBasePath = key.split("/")[2];
|
|
63
|
+
if (pageBasePath && otherBasePaths.includes(pageBasePath))
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const getPageContent = value;
|
|
67
|
+
pages[key] = await getPageContent();
|
|
50
68
|
})
|
|
51
69
|
);
|
|
52
70
|
const getPageState = (csrConfig) => {
|
|
@@ -96,13 +114,10 @@ const bootCsr = async (context, rootPath, entryPath = "/route") => {
|
|
|
96
114
|
}
|
|
97
115
|
});
|
|
98
116
|
}
|
|
99
|
-
const pathname = window.location.pathname;
|
|
100
|
-
const initialPath = import_client.device.lang + entryPath;
|
|
101
|
-
window.document.body.style.overflow = "hidden";
|
|
102
117
|
const getPathRoutes = (route, parentRootLayouts = [], parentLayouts = [], parentPaths = []) => {
|
|
103
118
|
const parentPath = parentPaths.filter((path2) => path2 !== "/").join("");
|
|
104
119
|
const currentPathSegment = /^\/\(.*\)$/.test(route.path) ? "" : route.path;
|
|
105
|
-
const isRoot =
|
|
120
|
+
const isRoot = baseLayoutPaths.includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
|
|
106
121
|
const path = parentPath + currentPathSegment;
|
|
107
122
|
const pathSegments = [...parentPaths, ...currentPathSegment ? [currentPathSegment] : []];
|
|
108
123
|
const RootLayouts = [...parentRootLayouts, ...isRoot && route.Layout ? [route.Layout] : []];
|
|
@@ -149,14 +164,9 @@ const bootCsr = async (context, rootPath, entryPath = "/route") => {
|
|
|
149
164
|
/* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null)
|
|
150
165
|
));
|
|
151
166
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (!el)
|
|
158
|
-
throw new Error("No root element");
|
|
159
|
-
const root = ReactDOM.createRoot(el);
|
|
160
|
-
root.render(/* @__PURE__ */ import_react.default.createElement(RouterProvider, null));
|
|
161
|
-
}
|
|
167
|
+
const el = document.getElementById("root");
|
|
168
|
+
if (!el)
|
|
169
|
+
throw new Error("No root element");
|
|
170
|
+
const root = ReactDOM.createRoot(el);
|
|
171
|
+
root.render(/* @__PURE__ */ import_react.default.createElement(RouterProvider, null));
|
|
162
172
|
};
|
package/esm/bootCsr.js
CHANGED
|
@@ -11,15 +11,33 @@ import React from "react";
|
|
|
11
11
|
import * as ReactDOM from "react-dom/client";
|
|
12
12
|
import { useCsrValues } from "./useCsrValues";
|
|
13
13
|
const supportLanguages = ["en", "ko"];
|
|
14
|
-
const bootCsr = async (context
|
|
14
|
+
const bootCsr = async (context) => {
|
|
15
|
+
window.document.body.style.overflow = "hidden";
|
|
16
|
+
const pathname = window.location.pathname;
|
|
17
|
+
if (pathname === "/404")
|
|
18
|
+
return;
|
|
15
19
|
const [, jwt] = await Promise.all([device.init({ supportLanguages }), storage.getItem("jwt")]);
|
|
20
|
+
if (!pathname.startsWith(`/${device.lang}`))
|
|
21
|
+
window.location.replace(`/${device.lang}${pathname}`);
|
|
16
22
|
if (jwt)
|
|
17
23
|
initAuth({ jwt });
|
|
18
24
|
Logger.verbose(`Set default language: ${device.lang}`);
|
|
25
|
+
const basePaths = process.env.basePaths?.split(",");
|
|
26
|
+
const currentBasePath = basePaths ? pathname.split("/")[2] : void 0;
|
|
27
|
+
if (currentBasePath && basePaths && !basePaths.includes(currentBasePath))
|
|
28
|
+
throw new Error(`Invalid path: ${pathname}`);
|
|
29
|
+
const baseLayoutPaths = ["/", "/:lang", ...currentBasePath ? [`/:lang/${currentBasePath}`] : []];
|
|
30
|
+
const otherBasePaths = basePaths?.filter((path) => path !== currentBasePath) ?? [];
|
|
19
31
|
const pages = {};
|
|
20
32
|
await Promise.all(
|
|
21
33
|
Object.entries(context).map(async ([key, value]) => {
|
|
22
|
-
|
|
34
|
+
if (basePaths) {
|
|
35
|
+
const pageBasePath = key.split("/")[2];
|
|
36
|
+
if (pageBasePath && otherBasePaths.includes(pageBasePath))
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const getPageContent = value;
|
|
40
|
+
pages[key] = await getPageContent();
|
|
23
41
|
})
|
|
24
42
|
);
|
|
25
43
|
const getPageState = (csrConfig) => {
|
|
@@ -69,13 +87,10 @@ const bootCsr = async (context, rootPath, entryPath = "/route") => {
|
|
|
69
87
|
}
|
|
70
88
|
});
|
|
71
89
|
}
|
|
72
|
-
const pathname = window.location.pathname;
|
|
73
|
-
const initialPath = device.lang + entryPath;
|
|
74
|
-
window.document.body.style.overflow = "hidden";
|
|
75
90
|
const getPathRoutes = (route, parentRootLayouts = [], parentLayouts = [], parentPaths = []) => {
|
|
76
91
|
const parentPath = parentPaths.filter((path2) => path2 !== "/").join("");
|
|
77
92
|
const currentPathSegment = /^\/\(.*\)$/.test(route.path) ? "" : route.path;
|
|
78
|
-
const isRoot =
|
|
93
|
+
const isRoot = baseLayoutPaths.includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
|
|
79
94
|
const path = parentPath + currentPathSegment;
|
|
80
95
|
const pathSegments = [...parentPaths, ...currentPathSegment ? [currentPathSegment] : []];
|
|
81
96
|
const RootLayouts = [...parentRootLayouts, ...isRoot && route.Layout ? [route.Layout] : []];
|
|
@@ -122,16 +137,11 @@ const bootCsr = async (context, rootPath, entryPath = "/route") => {
|
|
|
122
137
|
/* @__PURE__ */ React.createElement(React.Fragment, null)
|
|
123
138
|
));
|
|
124
139
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!el)
|
|
131
|
-
throw new Error("No root element");
|
|
132
|
-
const root = ReactDOM.createRoot(el);
|
|
133
|
-
root.render(/* @__PURE__ */ React.createElement(RouterProvider, null));
|
|
134
|
-
}
|
|
140
|
+
const el = document.getElementById("root");
|
|
141
|
+
if (!el)
|
|
142
|
+
throw new Error("No root element");
|
|
143
|
+
const root = ReactDOM.createRoot(el);
|
|
144
|
+
root.render(/* @__PURE__ */ React.createElement(RouterProvider, null));
|
|
135
145
|
};
|
|
136
146
|
export {
|
|
137
147
|
bootCsr
|