vike-lite 1.8.2 → 1.9.1
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/dist/__internal/server.d.mts +1 -1
- package/dist/__internal/shared.d.mts +1 -1
- package/dist/client/router.mjs +1 -2
- package/dist/{index-Dt5n1zWh.d.mts → index-ZDN-jKX_.d.mts} +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/server.d.mts +5 -1
- package/dist/server.mjs +13 -10
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as RenderContext, r as matchRoute, t as Config } from "../index-
|
|
1
|
+
import { n as RenderContext, r as matchRoute, t as Config } from "../index-ZDN-jKX_.mjs";
|
|
2
2
|
export { Config, RenderContext, matchRoute };
|
package/dist/client/router.mjs
CHANGED
|
@@ -10,8 +10,7 @@ function navigate(url, options) {
|
|
|
10
10
|
let finalUrl = url;
|
|
11
11
|
if (finalUrl.startsWith("/")) finalUrl = (BASE_URL.endsWith("/") ? BASE_URL.slice(0, -1) : BASE_URL) + (finalUrl === "/" ? "" : finalUrl);
|
|
12
12
|
globalThis.history.pushState(null, "", finalUrl);
|
|
13
|
-
globalThis.dispatchEvent(new
|
|
14
|
-
if (!options?.keepScrollPosition) globalThis.scrollTo(0, 0);
|
|
13
|
+
globalThis.dispatchEvent(new CustomEvent("vike-navigate", { detail: { keepScrollPosition: options?.keepScrollPosition } }));
|
|
15
14
|
}
|
|
16
15
|
//#endregion
|
|
17
16
|
export { navigate };
|
package/dist/index.d.mts
CHANGED
package/dist/server.d.mts
CHANGED
package/dist/server.mjs
CHANGED
|
@@ -20,7 +20,7 @@ const isProd = process.env.NODE_ENV === "production";
|
|
|
20
20
|
function withBase(file) {
|
|
21
21
|
return `${BASE_URL.replace(/\/$/, "")}/${file.replace(/^\//, "")}`;
|
|
22
22
|
}
|
|
23
|
-
function getAssets(route) {
|
|
23
|
+
function getAssets(route, nonce) {
|
|
24
24
|
if (!isProd) return {
|
|
25
25
|
cssLinks: "",
|
|
26
26
|
jsPreloads: "",
|
|
@@ -52,9 +52,10 @@ function getAssets(route) {
|
|
|
52
52
|
const criticalJs = [];
|
|
53
53
|
const sharedJs = [];
|
|
54
54
|
for (const [file, isCritical] of jsFiles) (isCritical ? criticalJs : sharedJs).push(file);
|
|
55
|
+
const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
|
|
55
56
|
return {
|
|
56
|
-
cssLinks: [...cssFiles].map((href) => `<link rel="stylesheet" href="${withBase(href)}">`).join(""),
|
|
57
|
-
jsPreloads: [...criticalJs.map((href) => `<link rel="modulepreload" href="${withBase(href)}" crossorigin fetchpriority="high">`), ...sharedJs.map((href) => `<link rel="modulepreload" href="${withBase(href)}" crossorigin>`)].join(""),
|
|
57
|
+
cssLinks: [...cssFiles].map((href) => `<link rel="stylesheet" href="${withBase(href)}"${nonceAttr}>`).join(""),
|
|
58
|
+
jsPreloads: [...criticalJs.map((href) => `<link rel="modulepreload" href="${withBase(href)}" crossorigin fetchpriority="high"${nonceAttr}>`), ...sharedJs.map((href) => `<link rel="modulepreload" href="${withBase(href)}" crossorigin${nonceAttr}>`)].join(""),
|
|
58
59
|
entryClient: withBase(manifest[virtualEntryClientKey].file)
|
|
59
60
|
};
|
|
60
61
|
}
|
|
@@ -95,7 +96,7 @@ async function buildPageContext(urlPathname, urlOriginal, isJsonRequest) {
|
|
|
95
96
|
LayoutModule
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
|
-
async function renderErrorPage(req, status, urlPathname, error) {
|
|
99
|
+
async function renderErrorPage(req, status, urlPathname, error, nonce) {
|
|
99
100
|
if (!store.errorRoute) return new Response(status === 404 ? "Not Found" : "Internal Server Error", { status });
|
|
100
101
|
try {
|
|
101
102
|
const { default: onRenderHtml } = await store.config.onRenderHtml();
|
|
@@ -119,7 +120,8 @@ async function renderErrorPage(req, status, urlPathname, error) {
|
|
|
119
120
|
Head: HeadModule ? HeadModule.Head ?? HeadModule.default : void 0,
|
|
120
121
|
pageTitleTag: `<title>${status === 404 ? "Page Not Found" : "Server Error"}</title>`,
|
|
121
122
|
serializedContext: serializeContext(pageContext),
|
|
122
|
-
assets: getAssets(store.errorRoute)
|
|
123
|
+
assets: getAssets(store.errorRoute, nonce),
|
|
124
|
+
nonce
|
|
123
125
|
});
|
|
124
126
|
return new Response(html, {
|
|
125
127
|
status,
|
|
@@ -130,7 +132,7 @@ async function renderErrorPage(req, status, urlPathname, error) {
|
|
|
130
132
|
return new Response(status === 404 ? "Not Found" : "Internal Server Error", { status });
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
|
-
async function renderPage(req) {
|
|
135
|
+
async function renderPage(req, { nonce } = {}) {
|
|
134
136
|
let { pathname } = new URL(req.url);
|
|
135
137
|
if (BASE_URL !== "/") {
|
|
136
138
|
const baseSlashed = BASE_URL.endsWith("/") ? BASE_URL : BASE_URL + "/";
|
|
@@ -147,7 +149,7 @@ async function renderPage(req) {
|
|
|
147
149
|
const resolved = await buildPageContext(targetPathname, req.url, isJsonRequest);
|
|
148
150
|
if (!resolved) {
|
|
149
151
|
if (isJsonRequest) return Response.json({ is404: true }, { status: 404 });
|
|
150
|
-
return renderErrorPage(req, 404, targetPathname);
|
|
152
|
+
return renderErrorPage(req, 404, targetPathname, nonce);
|
|
151
153
|
}
|
|
152
154
|
const { pageContext, route, PageModule, HeadModule, LayoutModule } = resolved;
|
|
153
155
|
if (isJsonRequest) return Response.json(pageContext);
|
|
@@ -159,7 +161,8 @@ async function renderPage(req) {
|
|
|
159
161
|
Layout: LayoutModule ? LayoutModule.Layout ?? LayoutModule.default : void 0,
|
|
160
162
|
pageTitleTag: pageContext.title ? `<title>${pageContext.title}</title>` : "",
|
|
161
163
|
serializedContext: serializeContext(pageContext),
|
|
162
|
-
assets: getAssets(route)
|
|
164
|
+
assets: getAssets(route, nonce),
|
|
165
|
+
nonce
|
|
163
166
|
});
|
|
164
167
|
return new Response(html, {
|
|
165
168
|
status: 200,
|
|
@@ -182,11 +185,11 @@ async function renderPage(req) {
|
|
|
182
185
|
isError: true,
|
|
183
186
|
reason: error.reason
|
|
184
187
|
}, { status: error.statusCode });
|
|
185
|
-
return renderErrorPage(req, error.statusCode, targetPathname, error.reason);
|
|
188
|
+
return renderErrorPage(req, error.statusCode, targetPathname, error.reason, nonce);
|
|
186
189
|
}
|
|
187
190
|
console.error("Render Error:", error);
|
|
188
191
|
if (isJsonRequest) return Response.json({ is500: true }, { status: 500 });
|
|
189
|
-
return renderErrorPage(req, 500, targetPathname, error);
|
|
192
|
+
return renderErrorPage(req, 500, targetPathname, error, nonce);
|
|
190
193
|
}
|
|
191
194
|
}
|
|
192
195
|
//#endregion
|