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)); }