From f8c0f5d320a6b4de2fef3c6f41b7ac3ced5edf19 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:57:26 +0800 Subject: [PATCH] fix(debugger): don't sync breakpoints to the backend while no project is open Before a project opens, and after it closes, loading the breakpoint list asked the backend to replace this window's breakpoints, which failed with "no project is open" and logged a warning on every such load. Without a project the backend holds none to replace. --- .../debugger/__tests__/startupBreakpoints.test.ts | 9 +++++++++ src/features/debugger/breakpoints/store.ts | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/features/debugger/__tests__/startupBreakpoints.test.ts b/src/features/debugger/__tests__/startupBreakpoints.test.ts index a5ee78a390..fc214eeca5 100644 --- a/src/features/debugger/__tests__/startupBreakpoints.test.ts +++ b/src/features/debugger/__tests__/startupBreakpoints.test.ts @@ -188,6 +188,15 @@ it("hands the window's whole list to the backend before startup, even after a fa ); }); +it("leaves the backend alone while no project is open", async () => { + loadBreakpoints(null); + await vi.advanceTimersByTimeAsync(200); + expect(ipc.debugReplaceBreakpoints).not.toHaveBeenCalled(); + loadBreakpoints("/p"); + await vi.advanceTimersByTimeAsync(0); + expect(ipc.debugReplaceBreakpoints).toHaveBeenCalledOnce(); +}); + it("flushes persisted breakpoints immediately after project loading", async () => { ipc.debugSetBreakpoints.mockResolvedValue({ status: "ok", data: [] }); localStorage.setItem( diff --git a/src/features/debugger/breakpoints/store.ts b/src/features/debugger/breakpoints/store.ts index d20fd58c46..380c14c721 100644 --- a/src/features/debugger/breakpoints/store.ts +++ b/src/features/debugger/breakpoints/store.ts @@ -138,8 +138,10 @@ async function drainBreakpoints() { /** Makes this window's whole list the backend's: files it no longer lists are cleared there. */ async function replaceBreakpoints() { - if (!isTauri() || useProject.getState().project?.trusted === false) return; - const { byFile, muted } = useBreakpoints.getState(); + // Without a project (before one opens, after it closes) the backend holds no breakpoints for + // this window and has none to clear. + const { root, byFile, muted } = useBreakpoints.getState(); + if (!isTauri() || root === null || useProject.getState().project?.trusted === false) return; const files = Object.fromEntries(Object.entries(byFile).map(([path, list]) => [path, toBackend(list, muted, path)])); await call(commands.debugReplaceBreakpoints(files)); }