Skip to content

Commit 567be77

Browse files
author
DevBot
committed
fix spa shell html metadata
1 parent cdcf3bc commit 567be77

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

packages/adapter-vite/__tests__/build.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,40 @@ Deno.test({
249249
},
250250
});
251251

252+
Deno.test({
253+
name: 'buildPlugin - SPA shell uses configured html title and lang',
254+
sanitizeOps: false,
255+
sanitizeResources: false,
256+
async fn() {
257+
const root = await Deno.makeTempDir();
258+
try {
259+
await Deno.mkdir(`${root}/app/routes`, { recursive: true });
260+
261+
const ctx = new OpenElementBuildContext({ mode: 'spa' });
262+
const plugin = buildPlugin({
263+
mode: 'spa',
264+
routesDir: 'app/routes',
265+
build: { outDir: 'dist' },
266+
html: {
267+
lang: 'zh-CN',
268+
title: 'Reader <Alpha>',
269+
},
270+
}, ctx);
271+
const config = makeConfig('build');
272+
config.root = root;
273+
callHook(plugin.configResolved, config);
274+
275+
await callAsyncHook(plugin.closeBundle);
276+
277+
const html = await Deno.readTextFile(`${root}/dist/index.html`);
278+
assertStringIncludes(html, '<html lang="zh-CN">');
279+
assertStringIncludes(html, '<title>Reader &lt;Alpha&gt;</title>');
280+
} finally {
281+
await Deno.remove(root, { recursive: true });
282+
}
283+
},
284+
});
285+
252286
Deno.test({
253287
name: 'buildPlugin - ssr.noExternal RegExp serialization writes to ctx',
254288
// Rolldown/Vite SSR build spawns dangling async fs.access (Deno.lstat) ops

packages/adapter-vite/src/build.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { OpenElementBuildContext } from './build-context.js';
1414
import { join } from 'node:path';
1515
import process from 'node:process';
1616
import { createLogger } from '@openelement/core/logger';
17+
import { escapeAttr, escapeHtml } from '@openelement/core';
1718
import { cleanSsrArtifacts, postProcessClientIslandBuild } from '@openelement/ssg';
1819
import { writeRouteManifest } from './route-manifest.js';
1920

@@ -76,13 +77,15 @@ export function buildPlugin(
7677
const outDirName = ctx.phase3.outDir || 'dist';
7778
const absOutDir = join(root, outDirName);
7879
const base = ctx.phase3.base || '/';
80+
const htmlLang = escapeAttr(ctx.phase3.html?.lang ?? 'en');
81+
const htmlTitle = escapeHtml(ctx.phase3.html?.title ?? 'openElement App');
7982

8083
// Generate SPA shell HTML
8184
const html = `<!DOCTYPE html>
82-
<html lang="en">
85+
<html lang="${htmlLang}">
8386
<head>
8487
<meta charset="UTF-8">
85-
<title>openElement Reader</title>
88+
<title>${htmlTitle}</title>
8689
</head>
8790
<body>
8891
<div id="root"></div>

0 commit comments

Comments
 (0)