diff --git a/.github/workflows/test-frontend.yaml b/.github/workflows/test-frontend.yaml index 8327c07..1d11d2e 100644 --- a/.github/workflows/test-frontend.yaml +++ b/.github/workflows/test-frontend.yaml @@ -5,6 +5,8 @@ on: - "src/**" - "package.json" - "tsconfig.json" + - "vite.config.ts" + - "package-lock.json" jobs: test: @@ -55,3 +57,20 @@ jobs: cache: npm - run: npm ci - run: npm run build + # Vite's esbuild pre-bundling can inject __publicField helper calls + # into maplibre-gl, breaking its Web Worker blob creation at runtime. + # Setting build.target and optimizeDeps.esbuildOptions.target to es2022+ + # in vite.config.ts prevents this by using native class fields instead. + # This step catches regressions from config changes, Vite/esbuild upgrades, + # or new dependencies that might reintroduce the problem. + # This check can be removed once maplibre-gl no longer creates Web Workers + # from inline blobs, or once Vite drops esbuild pre-bundling entirely. + # See https://github.com/tmshv/sphere/issues/102 + - name: Check for __publicField regression + run: | + if grep -r '__publicField' dist/assets/*.js; then + echo "ERROR: __publicField found in build output." + echo "Ensure build.target and optimizeDeps.esbuildOptions.target" + echo "are set to es2022 or higher in vite.config.ts." + exit 1 + fi diff --git a/CLAUDE.md b/CLAUDE.md index 6690fb1..6146a2d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -107,6 +107,10 @@ Available Tauri commands (invoked from frontend via `invoke()`): | `mbtiles_get_metadata` | Get MBTiles metadata/TileJSON | | `show_in_finder` | Open file location in system explorer | +## Important Build Constraints + +**esbuild target must be es2022+**: Both `build.target` and `optimizeDeps.esbuildOptions.target` in `vite.config.ts` must remain `es2022` or higher. Lower targets cause esbuild to inject `__publicField` helper calls into `maplibre-gl`, breaking its Web Worker blob creation at runtime. `tsconfig.json` `useDefineForClassFields` must stay `false` to match. CI checks the build output for this regression. Future versions of maplibre-gl may fix the inline blob worker approach, making this constraint unnecessary — check when upgrading. See [#102](https://github.com/tmshv/sphere/issues/102). + ## Known Issues / Technical Debt 1. **Error handling** - Error types discard context (e.g., `From` returns generic variant without details) diff --git a/tsconfig.json b/tsconfig.json index 0caa506..fdc7c58 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,10 @@ "compilerOptions": { "baseUrl": "./", "paths": { - "@/*": ["src/*"] + "@/*": ["src/*"], }, - "target": "ESNext", "useDefineForClassFields": true, + "target": "ES2022", "lib": ["DOM", "DOM.Iterable", "ESNext"], "allowJs": false, "skipLibCheck": true, @@ -19,7 +19,7 @@ "isolatedModules": true, "noEmit": true, "types": ["vitest/globals"], - "jsx": "react-jsx" + "jsx": "react-jsx", }, - "include": ["src"] + "include": ["src"], } diff --git a/vite.config.ts b/vite.config.ts index a8451cc..06befb2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -37,9 +37,14 @@ export default defineConfig({ // to make use of `TAURI_DEBUG` and other env variables // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand envPrefix: ["VITE_", "TAURI_"], + optimizeDeps: { + esbuildOptions: { + target: "es2022", + }, + }, build: { // Tauri supports es2021 - target: ["es2021", "chrome100", "safari13"], + target: ["es2022", "safari15"], // don't minify for debug builds minify: !process.env.TAURI_DEBUG ? "esbuild" : false, // produce sourcemaps for debug builds