fix(debugger): don't sync breakpoints to the backend while no project is open (#6215)

Before a project opens (a web page booting, a welcome window) and after one
closes, loadBreakpoints(null) asked the backend to replace this window's
breakpoints; with no project the call failed with "no project is open in this
window" and logged debugReplaceBreakpoints failed on every such load. Without a
project the backend holds no breakpoints for the window, so the sync now waits
until a project root is loaded.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-27 05:18:36 +08:00
1 джерело 6c7282b442
коміт 3d2b0946de
2 files changed
+13 -2

No files matched your search

+9
Переглянути файл
@@ -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(
+4 -2
Переглянути файл
@@ -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));
}