@void/vue 1.1.11 → 1.1.12

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.
Files changed (2) hide show
  1. package/dist/plugin.mjs +27 -10
  2. package/package.json +3 -3
package/dist/plugin.mjs CHANGED
@@ -3,7 +3,7 @@ import { generateComponentManifest, resolveEffectiveLayoutChain, resolvePagesDir
3
3
  import { existsSync, readFileSync, readdirSync } from "node:fs";
4
4
  import nodePath from "node:path";
5
5
  import { normalizePath } from "vite";
6
- import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, editIslandSource, findIslandImports, findStaticCssImports, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
6
+ import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, editIslandSource, findIslandImports, findStaticCssImports, hasIslandPages, islandStylesPlugin, recordIslandStyles, recordedIslandStyles, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
7
7
  //#region ../../node_modules/.pnpm/pathslash@0.1.0/node_modules/pathslash/dist/index.mjs
8
8
  const BACKSLASH_RE = /\\/g;
9
9
  const isWindows = process.platform === "win32";
@@ -119,6 +119,14 @@ function islandsPlugin(pagesDir, options) {
119
119
  }
120
120
  }
121
121
  },
122
+ buildEnd() {
123
+ recordIslandStyles(this, pageScan, pagesDir);
124
+ if (this.environment.config.consumer !== "client") return;
125
+ for (const id of recordedIslandStyles(pagesDir) ?? []) {
126
+ const vite = this.getModuleInfo(id)?.meta.vite;
127
+ if (vite?.cssScopeTo) delete vite.cssScopeTo;
128
+ }
129
+ },
122
130
  resolveId: {
123
131
  filter: { id: /^virtual:void-islands-(renderer|client)$/ },
124
132
  handler(source) {
@@ -137,7 +145,7 @@ function islandsPlugin(pagesDir, options) {
137
145
  }
138
146
  if (id === "\0" + ISLANDS_CLIENT_ENTRY_ID) {
139
147
  if (!pageScan) return "";
140
- return generateIslandClientEntry(islandManifest, islandCssFiles, isDev);
148
+ return generateIslandClientEntry(islandManifest, islandCssFiles, recordedIslandStyles(pagesDir), islandManifest.size > 0 || computePagesNeedingClientJS(pageScan, pagesDir, resolvedConfig).size > 0, isDev);
141
149
  }
142
150
  }
143
151
  },
@@ -180,15 +188,15 @@ function islandsPlugin(pagesDir, options) {
180
188
  }
181
189
  }
182
190
  },
183
- config(_, env) {
191
+ async config(_, env) {
184
192
  if (!existsSync(pagesDir)) return;
185
193
  if (env.command === "serve") return { optimizeDeps: { include: ["vue"] } };
186
- if (needsIslandClientBundle(pagesDir, /\.island\.vue$/, true)) return { environments: { client: { build: {
194
+ if (await hasIslandPages(root, pagesDir)) return { environments: { client: { build: {
187
195
  manifest: true,
188
196
  rollupOptions: { input: { "islands-client": ISLANDS_CLIENT_ENTRY_ID } }
189
197
  } } } };
190
198
  }
191
- }];
199
+ }, islandStylesPlugin(pagesDir)];
192
200
  }
193
201
  function generateIslandRenderer(scan, pagesDir, mdScriptIds, pagesNeedingClientJS) {
194
202
  const mdScriptIdsCode = `const __mdClientScriptIds = new Set(${JSON.stringify([...mdScriptIds])});`;
@@ -197,6 +205,7 @@ function generateIslandRenderer(scan, pagesDir, mdScriptIds, pagesNeedingClientJ
197
205
  import { createSSRApp, h, reactive, provide } from "vue";
198
206
  import { renderToString } from "vue/server-renderer";
199
207
  import { renderHeadToString, renderHtmlAttrs, renderBodyAttrs } from "void/pages-head";
208
+ import { islandFrontmatterScript } from "void/pages-server";
200
209
 
201
210
  ${generateComponentManifest(scan, pagesDir)}
202
211
  ${mdScriptIdsCode}
@@ -233,6 +242,11 @@ export async function renderIslandPage(pageObj, assetTags) {
233
242
  });
234
243
 
235
244
  const html = await renderToString(app);
245
+ // Islands hydrate as separate roots. Send the page frontmatter so their
246
+ // useFrontmatter() returns the same value in the browser.
247
+ const __frontmatterScript = __pagesNeedingClientJS.has(pageObj.component) && html.includes("data-island=")
248
+ ? islandFrontmatterScript(__pageModule.frontmatter)
249
+ : "";
236
250
  const __mdScriptAttr = __mdClientScriptIds.has(pageObj.component) ? \` data-md-script="\${escapeAttr(pageObj.component)}"\` : "";
237
251
  const headHtml = pageObj.head ? renderHeadToString(pageObj.head) : "";
238
252
  const htmlAttrs = pageObj.head ? renderHtmlAttrs(pageObj.head) : "";
@@ -243,19 +257,19 @@ export async function renderIslandPage(pageObj, assetTags) {
243
257
  <head>\${headHtml}\${assetTags.css}\${__pagesNeedingClientJS.has(pageObj.component) ? assetTags.preloads : ""}</head>
244
258
  <body\${bodyAttrs}>
245
259
  <div id="app"\${__mdScriptAttr}>\${html}</div>
246
- \${__pagesNeedingClientJS.has(pageObj.component) ? assetTags.body : ""}
260
+ \${__frontmatterScript}\${__pagesNeedingClientJS.has(pageObj.component) ? assetTags.body : ""}
247
261
  </body>
248
262
  </html>\`;
249
263
  }
250
264
  `;
251
265
  }
252
- function generateIslandClientEntry(manifest, cssFiles, isDev) {
266
+ function generateIslandClientEntry(manifest, cssFiles, styles, needsRuntime, isDev) {
253
267
  const entries = [...manifest.values()];
254
268
  const uniqueIslands = /* @__PURE__ */ new Map();
255
269
  for (const entry of entries) uniqueIslands.set(entry.islandId, entry.componentPath);
256
270
  const lines = [];
257
- lines.push("import { initIslands } from \"void/pages-client\";");
258
- if (!isDev) {
271
+ if (!isDev && styles) for (const id of styles) lines.push(`import ${JSON.stringify(id)};`);
272
+ else if (!isDev) {
259
273
  const styleRe = /<style\b([^>]*)>/g;
260
274
  for (const file of cssFiles) {
261
275
  const content = readFileSync(file, "utf-8");
@@ -275,14 +289,17 @@ function generateIslandClientEntry(manifest, cssFiles, isDev) {
275
289
  for (const item of findStaticCssImports(content, file)) lines.push(rewriteCssImportForVirtualModule(item.statement, item.specifier, file));
276
290
  }
277
291
  }
292
+ if (!needsRuntime && !isDev) return lines.join("\n");
293
+ lines.push("import { initIslands } from \"void/pages-client\";");
278
294
  lines.push("const islands = {");
279
295
  for (const [id, path] of uniqueIslands) lines.push(` ${JSON.stringify(id)}: () => import(${JSON.stringify(path)}),`);
280
296
  lines.push("};");
281
297
  lines.push(`
282
- async function hydrateIsland(el, mod, props) {
298
+ async function hydrateIsland(el, mod, props, frontmatter) {
283
299
  const { createSSRApp, h } = await import("vue");
284
300
  const Component = mod.default || mod;
285
301
  const app = createSSRApp({ render: () => h(Component, props) });
302
+ app.provide("__void_frontmatter", frontmatter);
286
303
  app.mount(el);
287
304
  el.setAttribute("data-hydrated", "true");
288
305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@void/vue",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "Vue pages, server rendering, forms, and navigation for Void.",
5
5
  "homepage": "https://void.cloud",
6
6
  "bugs": {
@@ -41,12 +41,12 @@
41
41
  "pathslash": "^0.1.0",
42
42
  "vite": "npm:@voidzero-dev/vite-plus-core@1.2.0",
43
43
  "vite-plus": "1.2.0",
44
- "void": "1.1.11",
44
+ "void": "1.1.12",
45
45
  "vue": "^3.5.44"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "vite": "^8.0.0",
49
- "void": "1.1.11",
49
+ "void": "1.1.12",
50
50
  "vue": "^3.5.0"
51
51
  },
52
52
  "scripts": {