vike-lite 1.1.1 → 1.1.3

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/server.mjs CHANGED
@@ -26,7 +26,7 @@ var AbortRender = class extends Error {
26
26
  //#endregion
27
27
  //#region src/server/renderPage.tsx
28
28
  const isProd = process.env.NODE_ENV === "production";
29
- function getAssets(pageModuleId) {
29
+ function getAssets(route) {
30
30
  if (!isProd) return {
31
31
  cssLinks: "",
32
32
  jsPreloads: "",
@@ -44,14 +44,16 @@ function getAssets(pageModuleId) {
44
44
  if (visitedKeys.has(key)) return;
45
45
  visitedKeys.add(key);
46
46
  const chunk = manifest[key];
47
- if (!chunk) throw new Error(`Asset not found in manifest for key: ${key}`);
48
47
  jsFiles.add(chunk.file);
49
48
  if (chunk.css) for (const css of chunk.css) cssFiles.add(css);
50
49
  if (chunk.imports) for (const imp of chunk.imports) collectAssets(imp);
51
50
  }
52
51
  const virtualEntryClientKey = getVirtualEntryClientKey();
53
52
  collectAssets(virtualEntryClientKey);
54
- collectAssets(pageModuleId.replace("@/", ""));
53
+ const { page, layout, head } = route;
54
+ collectAssets(page.replace("@/", ""));
55
+ if (head) collectAssets(head.replace("@/", ""));
56
+ if (layout) collectAssets(layout.replace("@/", ""));
55
57
  return {
56
58
  cssLinks: [...cssFiles].map((href) => `<link rel="stylesheet" href="/${href}">`).join(""),
57
59
  jsPreloads: [...jsFiles].map((href) => `<link rel="modulepreload" href="/${href}">`).join(""),
@@ -119,7 +121,7 @@ async function renderErrorPage(req, status, urlPathname, error) {
119
121
  Head: HeadModule ? HeadModule.Head ?? HeadModule.default : void 0,
120
122
  pageTitleTag: `<title>${status === 404 ? "Page Not Found" : "Server Error"}</title>`,
121
123
  serializedContext: serializeContext(pageContext),
122
- assets: getAssets(store.errorRoute.page)
124
+ assets: getAssets(store.errorRoute)
123
125
  });
124
126
  return new Response(html, {
125
127
  status,
@@ -147,14 +149,14 @@ async function renderPage(req) {
147
149
  const { pageContext, route, PageModule, HeadModule, LayoutModule } = resolved;
148
150
  if (isJsonRequest) return Response.json(pageContext);
149
151
  const { default: onRenderHtml } = await store.config.onRenderHtml();
150
- const html = await onRenderHtml({
152
+ const html = onRenderHtml({
151
153
  pageContext,
152
154
  Page: PageModule.Page ?? PageModule.default,
153
155
  Head: HeadModule ? HeadModule.Head ?? HeadModule.default : void 0,
154
156
  Layout: LayoutModule ? LayoutModule.Layout ?? LayoutModule.default : void 0,
155
157
  pageTitleTag: pageContext.title ? `<title>${pageContext.title}</title>` : "",
156
158
  serializedContext: serializeContext(pageContext),
157
- assets: getAssets(route.page)
159
+ assets: getAssets(route)
158
160
  });
159
161
  return new Response(html, {
160
162
  status: 200,
package/dist/vite.mjs CHANGED
@@ -152,9 +152,10 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
152
152
  const isSSR = options.ssr;
153
153
  let code = `import { onRenderHtml } from '${virtualAdapterId}';\nexport const config = { onRenderHtml };\nexport const routes = [\n`;
154
154
  for (const r of routes) {
155
- code += `{path:'${r.path}',page:'${r.page}',hasData:${r.hasData},hasTitle:${r.hasTitle},Page:()=>import('${r.page}'),`;
156
- if (r.head) code += `Head:()=>import('${r.head}'),`;
157
- if (r.layout) code += `Layout:()=>import('${r.layout}'),`;
155
+ code += `{path:'${r.path}',page:'${r.page}',Page:()=>import('${r.page}'),`;
156
+ if (r.head) code += `head:'${r.head}',Head:()=>import('${r.head}'),`;
157
+ if (r.layout) code += `layout:'${r.layout}',Layout:()=>import('${r.layout}'),`;
158
+ code += `hasData:${r.hasData},hasTitle:${r.hasTitle},`;
158
159
  if (isSSR) {
159
160
  if (r.hasData) code += `data:()=>import('${r.page.replace("+Page.tsx", "+data.ts")}'),`;
160
161
  if (r.hasTitle) code += `title:()=>import('${r.page.replace("+Page.tsx", "+title.ts")}'),`;
@@ -165,8 +166,8 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
165
166
  if (errorRoute) {
166
167
  const e = errorRoute;
167
168
  code += `export const errorRoute={path:'${e.path}',page:'${e.page}',Page:()=>import('${e.page}'),`;
168
- if (e.layout) code += `Layout:()=>import('${e.layout}'),`;
169
- if (e.head) code += `Head:()=>import('${e.head}'),`;
169
+ if (e.layout) code += `layout:'${e.layout}',Layout:()=>import('${e.layout}'),`;
170
+ if (e.head) code += `head:'${e.head}',Head:()=>import('${e.head}'),`;
170
171
  code += "};\n";
171
172
  } else code += "export const errorRoute=null;\n";
172
173
  return code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",