From 11a433c25e559467e44cf4911dd7d0a6ecb37e53 Mon Sep 17 00:00:00 2001 From: Hamdi LAADHARI Date: Mon, 7 Sep 2026 15:35:07 +0200 Subject: [PATCH] fix(preload): bundle the preload so it loads under Electron's sandbox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since ef10eda the preload imports CHANNELS from ./ipc-types, which tsc compiles to require("./ipc-types"). Electron sandboxes the renderer by default, and a sandboxed preload can only require Electron's own builtins — never a relative file. So the preload threw on load, contextBridge never ran, window.electronAPI was undefined, and the renderer crashed on its first property access. The window came up blank. Nothing caught it: the type-checker is happy, the unit tests never boot Electron, and `npm run pack` builds the app without launching it. Bundle the preload with esbuild as an IIFE instead, so it reaches the sandbox self-contained. tsc still type-checks it via tsconfig.main.json, so the single-source-of-truth IPC contract that ef10eda introduced is kept intact — this only changes how the file is emitted. No released version is affected; v1.4.0 and earlier predate the refactor. Co-Authored-By: Claude Opus 5 --- package-lock.json | 1 + package.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index b1a52e5..f879b4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "electron": "^27.1.3", "electron-builder": "^24.9.1", "electron-icon-builder": "^2.0.1", + "esbuild": "^0.21.5", "jsdom": "^29.1.1", "postcss": "^8.4.32", "sharp": "^0.35.3", diff --git a/package.json b/package.json index ba9fa89..790f8f4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "dev:electron": "wait-on http://localhost:3000 && electron .", "build": "npm run build:vite && npm run build:electron", "build:vite": "vite build", - "build:electron": "tsc -p tsconfig.main.json", + "build:electron": "tsc -p tsconfig.main.json && npm run build:preload", + "build:preload": "esbuild electron/preload.ts --bundle --platform=browser --format=iife --external:electron --outfile=dist/preload.js", "build:icons": "node scripts/build-icons.js", "test": "vitest run", "test:watch": "vitest", @@ -52,6 +53,7 @@ "electron": "^27.1.3", "electron-builder": "^24.9.1", "electron-icon-builder": "^2.0.1", + "esbuild": "^0.21.5", "jsdom": "^29.1.1", "postcss": "^8.4.32", "sharp": "^0.35.3",