From 7e88f6bb18072a60c746e0f4752eef0a580a3af4 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Sun, 20 Sep 2026 16:19:28 +1000 Subject: [PATCH] perf(desktop): bundle the renderer's initial module graph as one chunk (#50110) --- packages/desktop/electron.vite.config.ts | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/desktop/electron.vite.config.ts b/packages/desktop/electron.vite.config.ts index 6dd68067f33..2db653a6f38 100644 --- a/packages/desktop/electron.vite.config.ts +++ b/packages/desktop/electron.vite.config.ts @@ -28,6 +28,29 @@ const sentry = }) : false +// Every module the entry reaches through static imports lands in one chunk. Automatic splitting +// otherwise fragments the initial graph into ~50 files shared with lazy routes, and each file costs +// the renderer a main-thread request round trip through the main process before first paint. +type ChunkingContext = { getModuleInfo(id: string): { isEntry: boolean; importers: readonly string[] } | null } +const initialGraph = new WeakMap>() +function inInitialGraph(id: string, ctx: ChunkingContext) { + const memo = initialGraph.get(ctx) ?? new Map() + initialGraph.set(ctx, memo) + const visit = (id: string, path: Set): boolean => { + const known = memo.get(id) + if (known !== undefined) return known + if (path.has(id)) return false + const info = ctx.getModuleInfo(id) + if (!info) return false + path.add(id) + const result = info.isEntry || info.importers.some((importer) => visit(importer, path)) + path.delete(id) + memo.set(id, result) + return result + } + return visit(id, new Set()) +} + export default defineConfig(({ command }) => ({ main: { resolve: { @@ -110,6 +133,11 @@ const require = __cjs_mod__.createRequire(import.meta.url); input: { main: "src/renderer/index.html", }, + output: { + codeSplitting: { + groups: [{ name: (id, ctx) => (inInitialGraph(id, ctx) ? "app" : null), priority: 10 }], + }, + }, }, }, },