diff --git a/apps/app/vite.dev.config.ts b/apps/app/vite.dev.config.ts index 2d4743c12..0de0a718c 100644 --- a/apps/app/vite.dev.config.ts +++ b/apps/app/vite.dev.config.ts @@ -1,4 +1,32 @@ -import { defineConfig } from "vite"; +import { defineConfig, type Plugin } from "vite"; +import { readFileSync } from "node:fs"; + +// QA instrumentation for issue #1676: delay proxied API requests whose URL +// contains `match` by `ms` when /tmp/bb-reports/issues/1676/repro/delay.json +// exists ({"match":"...","ms":4000}). Re-read on every request so it can be +// toggled without restarting Vite. +function qaDelayPlugin(): Plugin { + return { + name: "qa-delay-1676", + configureServer(server) { + server.middlewares.use((req, _res, next) => { + let spec: { match?: string; ms?: number } | null = null; + try { + spec = JSON.parse( + readFileSync("/tmp/bb-reports/issues/1676/repro/delay.json", "utf8"), + ); + } catch { + spec = null; + } + if (spec?.match && spec.ms && (req.url ?? "").includes(spec.match)) { + setTimeout(next, spec.ms); + return; + } + next(); + }); + }, + }; +} import { loadViteDevConfig } from "@bb/config/vite-dev"; import { sharedViteConfig } from "./vite.config.js"; @@ -9,6 +37,7 @@ const devWebSocketBrowserHostPortDefine = JSON.stringify( export default defineConfig({ ...sharedViteConfig, + plugins: [...(sharedViteConfig.plugins ?? []), qaDelayPlugin()], // Match the production CSS pipeline in dev. In particular, this lowers // Tailwind's nested conditional rules for Safari versions that parse // color-mix() but do not reliably apply nested @supports declarations.