Skip to content

Commit 197daf6

Browse files
authored
fix(bundled-dev): declare utf-8 charset in fallback page (#23846)
1 parent 0075c4b commit 197daf6

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎packages/vite/src/node/server/middlewares/indexHtml.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,14 @@ function preTransformRequest(server: ViteDevServer, url: string) {
565565

566566
async function generateFallbackHtml(server: ViteDevServer) {
567567
const hmrRuntime = await getHmrImplementation(server.config)
568+
// The charset must be declared: the inlined HMR runtime contains non-ASCII
569+
// characters, and without it browsers may decode this page with a legacy
570+
// encoding (e.g. GBK), corrupting the inline module script below.
568571
return /* html */ `
569572
<!DOCTYPE html>
570573
<html lang="en">
571574
<head>
575+
<meta charset="utf-8" />
572576
<script>globalThis.__vite_is_fallback_page__ = true</script>
573577
<script type="module">
574578
${hmrRuntime.replaceAll('</script>', '<\\/script>')}

0 commit comments

Comments
 (0)