From bdf4436899c9ff3f900d6ec5973d814e6e209d43 Mon Sep 17 00:00:00 2001 From: Huarch Date: Mon, 17 Aug 2026 20:22:35 +0800 Subject: [PATCH] fix: preserve backdrop filter in production --- package.json | 3 ++- scripts/verify-production-css.mjs | 35 +++++++++++++++++++++++++++++++ vite.config.ts | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 scripts/verify-production-css.mjs diff --git a/package.json b/package.json index 6484e37..db839f6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "packageManager": "pnpm@11.8.0", "scripts": { "dev": "vite", - "build": "tsc --noEmit && vite build && pnpm build:tts", + "build": "tsc --noEmit && vite build && pnpm build:verify-css && pnpm build:tts", + "build:verify-css": "node scripts/verify-production-css.mjs", "build:tts": "esbuild server/edge-tts-server.ts --bundle --platform=node --format=cjs --outfile=dist-server/edge-tts-server.cjs", "preview": "vite preview", "typecheck": "tsc --noEmit", diff --git a/scripts/verify-production-css.mjs b/scripts/verify-production-css.mjs new file mode 100644 index 0000000..ca33105 --- /dev/null +++ b/scripts/verify-production-css.mjs @@ -0,0 +1,35 @@ +import { readdir, readFile } from "node:fs/promises"; +import { stdout } from "node:process"; +import { fileURLToPath, URL } from "node:url"; +import path from "node:path"; + +const assetsDirectory = fileURLToPath(new URL("../dist/assets/", import.meta.url)); +const assetNames = await readdir(assetsDirectory); +const stylesheetName = assetNames.find((name) => /^index-.*\.css$/.test(name)); + +if (!stylesheetName) { + throw new Error("Production CSS verification failed: index stylesheet was not emitted."); +} + +const stylesheet = await readFile(path.join(assetsDirectory, stylesheetName), "utf8"); +const selector = ".agent-panel-shell.acrylic-panel"; +const selectorOffset = stylesheet.indexOf(selector); +const ruleStart = stylesheet.indexOf("{", selectorOffset); +const ruleEnd = stylesheet.indexOf("}", ruleStart); + +if (selectorOffset < 0 || ruleStart < 0 || ruleEnd < 0) { + throw new Error(`Production CSS verification failed: ${selector} rule is missing.`); +} + +const declarations = stylesheet + .slice(ruleStart + 1, ruleEnd) + .split(";") + .map((declaration) => declaration.trim()); + +if (!declarations.some((declaration) => declaration.startsWith("backdrop-filter:"))) { + throw new Error( + "Production CSS verification failed: the standard backdrop-filter declaration was removed." + ); +} + +stdout.write(`Verified standard backdrop-filter in ${stylesheetName}.\n`); diff --git a/vite.config.ts b/vite.config.ts index f58ddf5..aca7172 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -46,7 +46,7 @@ export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ""); return { - plugins: [runtimeConfigPlugin(env), react(), tailwindcss()], + plugins: [runtimeConfigPlugin(env), react(), tailwindcss({ optimize: false })], server: { allowedHosts: ["next.demo.waternetwork.cn"] },