From 01a5e948beb984e0ea19f8939d4a5ae2b242f117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Thu, 19 Nov 2026 10:18:16 +0000 Subject: [PATCH] fix(core): page runtimes carry no wide characters, so pages stay one byte a char (#8239) * fix(inspector): the page runtime carries no wide characters, so inspected pages stay one byte a char * fix(core): the inlined page runtime carries no wide characters either * fix(core): the wide-character check lives in core, which every runtime build image copies --- .../core/scripts/build-hyperframes-runtime-artifact.ts | 7 +++++++ packages/core/scripts/page-script-one-byte.mjs | 4 ++++ packages/core/src/runtime/editing/editElement.ts | 2 +- packages/inspector/build.mjs | 9 +++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 packages/core/scripts/page-script-one-byte.mjs diff --git a/packages/core/scripts/build-hyperframes-runtime-artifact.ts b/packages/core/scripts/build-hyperframes-runtime-artifact.ts index f07715a8e9..f63b3564ba 100644 --- a/packages/core/scripts/build-hyperframes-runtime-artifact.ts +++ b/packages/core/scripts/build-hyperframes-runtime-artifact.ts @@ -9,6 +9,7 @@ import { } from "../src/inline-scripts/hyperframe"; import { RUNTIME_ESBUILD_DEFINE } from "../src/inline-scripts/hyperframesRuntime.engine"; import { writeGeneratedFile } from "./writeGeneratedFile.js"; +import { firstCharacterThatMakesPagesTwoByte } from "./page-script-one-byte.mjs"; const thisDir = dirname(fileURLToPath(import.meta.url)); const distDir = resolve(thisDir, "../dist"); @@ -20,6 +21,12 @@ const runtimeSourceRaw = loadHyperframeRuntimeSource(); if (runtimeSourceRaw === null) { throw new Error("Cannot build runtime artifact: entry.ts not found at expected path"); } +const wide = firstCharacterThatMakesPagesTwoByte(runtimeSourceRaw); +if (wide) { + throw new Error( + `the page runtime has ${wide}: every page it is inlined into would be stored at two bytes a character`, + ); +} const runtimeSource = `${runtimeSourceRaw}\n`; const runtimeSha256 = createHash("sha256").update(runtimeSource, "utf8").digest("hex"); const buildId = process.env.HYPERFRAME_RUNTIME_BUILD_ID?.trim() || "dev"; diff --git a/packages/core/scripts/page-script-one-byte.mjs b/packages/core/scripts/page-script-one-byte.mjs new file mode 100644 index 0000000000..f2ef055246 --- /dev/null +++ b/packages/core/scripts/page-script-one-byte.mjs @@ -0,0 +1,4 @@ +export function firstCharacterThatMakesPagesTwoByte(text) { + const wide = /[\u{100}-\u{10ffff}]/u.exec(text); + return wide && `U+${wide[0].codePointAt(0).toString(16)} at ${wide.index}`; +} diff --git a/packages/core/src/runtime/editing/editElement.ts b/packages/core/src/runtime/editing/editElement.ts index 568ae4a886..a362beed3d 100644 --- a/packages/core/src/runtime/editing/editElement.ts +++ b/packages/core/src/runtime/editing/editElement.ts @@ -19,7 +19,7 @@ export type EditElementResult = { export const MAX_EDIT_ENTRIES = 64; export const MAX_EDIT_VALUE = 200_000; -const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080-￿-]+)$/; +const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080-\uffff-]+)$/; const DATA_ATTRIBUTE = /^data-[a-z0-9_-]+$/; const PANEL_ATTRIBUTES = new Set(["loop", "muted", "alt", "title", "src"]); const MEDIA_TAGS = new Set(["img", "video", "audio"]); diff --git a/packages/inspector/build.mjs b/packages/inspector/build.mjs index 1b5796a22f..786d3b60b9 100644 --- a/packages/inspector/build.mjs +++ b/packages/inspector/build.mjs @@ -4,6 +4,7 @@ import { copyFileSync, readFileSync, rmSync } from "node:fs"; import { createRequire } from "node:module"; import { fileURLToPath } from "node:url"; import { build } from "esbuild"; +import { firstCharacterThatMakesPagesTwoByte } from "../core/scripts/page-script-one-byte.mjs"; import { rewriteRelativeImportExtensions } from "../../scripts/rewrite-relative-import-extensions.mjs"; const at = (path) => fileURLToPath(new URL(path, import.meta.url)); @@ -42,8 +43,16 @@ await Promise.all([ bundle: true, platform: "browser", format: "iife", + minifyWhitespace: true, }), ]); +const wide = firstCharacterThatMakesPagesTwoByte(readFileSync(at("./dist/inspection.js"), "utf8")); +if (wide) { + rmSync(at("./dist/inspection.js")); + throw new Error( + `dist/inspection.js has ${wide}: every page it joins would be stored at two bytes a character`, + ); +} // Declarations keep the packages/ layout under dist/types, so their relative imports still resolve once packed. rmSync(at("./dist/types"), { recursive: true, force: true }); const tsc = createRequire(import.meta.url).resolve("typescript/bin/tsc");