claude-prism/apps/desktop/vite.config.ts
delibae bdc57978ba fix: resolve macOS 12 window not showing due to WebKit top-level-await bug
On macOS 12 (Monterey), the app launches but no main window appears.
The root cause is WebKit bug #242740: Safari 15's WKWebView has a race
condition with top-level await in ES modules, causing silent JS failure
that prevents `getCurrentWindow().show()` from ever being called.

Three complementary fixes:

1. Change Vite build target from `esnext` to `safari14` (Tauri recommended)
   and add `vite-plugin-top-level-await` to transform TLA into compatible
   Promise chains, avoiding the WebKit bug entirely.

2. Replace top-level `await import("./App")` in main.tsx with a `.then()`
   chain, removing TLA dependency at the source level.

3. Add a Rust-side 8-second timeout safety net in `setup()` that
   force-shows the main window if the frontend JS fails to do so,
   preventing permanently hidden windows regardless of the failure cause.

Closes #95

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:57:52 +09:00

44 lines
969 B
TypeScript

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import topLevelAwait from "vite-plugin-top-level-await";
import path from "node:path";
const host = process.env.TAURI_DEV_HOST;
export default defineConfig({
plugins: [react(), topLevelAwait()],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
worker: {
format: "es",
},
optimizeDeps: {
exclude: ["mupdf"],
},
clearScreen: false,
server: {
port: 1420,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
ignored: ["**/src-tauri/**"],
},
},
envPrefix: ["VITE_", "TAURI_"],
build: {
target:
process.env.TAURI_ENV_PLATFORM === "windows" ? "chrome105" : "safari14",
minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false,
sourcemap: !!process.env.TAURI_ENV_DEBUG,
},
});