From 05c225c186bfc194e2056cf836c2f290d56765e0 Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sat, 28 Nov 2026 22:10:30 -0500 Subject: [PATCH 1/2] Show the Canvas leave guards above the note panel The discard and saving dialogs in canvas.tsx were always mounted, so the note panel's portal landed over them and hid "Discard changes". Mount them on demand, as DocumentSidePanel does for its own guard. Update canvas-note-panel.spec.ts for the non-modal panel, autosave, and the saveDocContent action. Co-Authored-By: Claude Sonnet 5.5 --- app/src/routes/canvas.tsx | 83 +++++++++++++------------ app/tests/e2e/canvas-note-panel.spec.ts | 45 ++++++++++---- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/app/src/routes/canvas.tsx b/app/src/routes/canvas.tsx index 36256474..ba14dfa4 100644 --- a/app/src/routes/canvas.tsx +++ b/app/src/routes/canvas.tsx @@ -828,45 +828,50 @@ const CanvasRoute: VoidComponent = () => { } }} /> - { - setDiscardDialogOpen(open); - if (!open) setPendingSelectedId(undefined); - }} - title={ - activeEditor()?.api.error() - ? "This note didn't save" - : "Discard unsaved changes?" - } - description={ - activeEditor()?.api.error() - ? "Your latest changes aren't saved. If you stay, this note keeps retrying. If you leave now, they will be lost." - : "Your unsaved changes will be lost if you leave this note." - } - confirmLabel={ - activeEditor()?.api.error() ? "Leave" : "Discard changes" - } - cancelLabel={activeEditor()?.api.error() ? "Stay" : "Keep editing"} - onConfirm={() => { - setSelectedId(pendingSelectedId()); - setPendingSelectedId(undefined); - }} - /> - setSaveInProgressDialogOpen(false)} - > - Keep editing - - } - /> + {/* Mounted on demand so their portals land above the panel's. */} + + { + setDiscardDialogOpen(open); + if (!open) setPendingSelectedId(undefined); + }} + title={ + activeEditor()?.api.error() + ? "This note didn't save" + : "Discard unsaved changes?" + } + description={ + activeEditor()?.api.error() + ? "Your latest changes aren't saved. If you stay, this note keeps retrying. If you leave now, they will be lost." + : "Your unsaved changes will be lost if you leave this note." + } + confirmLabel={ + activeEditor()?.api.error() ? "Leave" : "Discard changes" + } + cancelLabel={activeEditor()?.api.error() ? "Stay" : "Keep editing"} + onConfirm={() => { + setSelectedId(pendingSelectedId()); + setPendingSelectedId(undefined); + }} + /> + + + setSaveInProgressDialogOpen(false)} + > + Keep editing + + } + /> + ); diff --git a/app/tests/e2e/canvas-note-panel.spec.ts b/app/tests/e2e/canvas-note-panel.spec.ts index e87328fe..94a480c6 100644 --- a/app/tests/e2e/canvas-note-panel.spec.ts +++ b/app/tests/e2e/canvas-note-panel.spec.ts @@ -9,9 +9,10 @@ import { waitForAppReady } from "./helpers/readiness"; import { holdNextServerAction, settled } from "./helpers/server-actions"; // Regressions on the real /canvas route and its keyed note panel. -// PR #44: closing the panel (close button, backdrop, or Escape) used to drop -// unsaved edits and could close mid-save; Escape inside the guard dialog must -// not close the panel. +// PR #44: leaving the note (close button, Escape, or opening another note) used +// to drop unsaved edits and could happen mid-save; Escape inside the guard +// dialog must not close the panel. The panel is non-modal, so it has no +// backdrop and the map and search stay usable beside it. // PR #43: a disposed panel viewer must not report its late failure over the // note that replaced it. // @@ -37,6 +38,19 @@ const openFromRail = async (page: Page, title: string) => { await page.waitForLoadState("networkidle"); }; +// DocumentEditor saves 1.5s after the last keystroke, which races any case that +// needs an unsaved draft. This drops that one timer; if the delay changes, the +// unsaved case fails on its dialog or its no-save check. +const AUTOSAVE_DELAY_MS = 1500; +const holdAutosave = (page: Page) => + page.evaluate((autosaveMs) => { + const schedule = window.setTimeout.bind(window); + window.setTimeout = ((handler: TimerHandler, ms?: number, ...args) => + ms === autosaveMs + ? 0 + : schedule(handler, ms, ...args)) as typeof window.setTimeout; + }, AUTOSAVE_DELAY_MS); + const typeIntoEditor = async (page: Page, text: string) => { await editor(page).click(); await expect(editor(page)).toBeFocused(); @@ -48,8 +62,13 @@ const typeIntoEditor = async (page: Page, text: string) => { ).toBeVisible(); }; -const clickBackdrop = (page: Page) => - panel(page).click({ position: { x: 10, y: 200 } }); +// The panel covers the rail, so search is how to ask for another note by name: +// Enter on a single match opens it. +const openFromSearch = async (page: Page, title: string) => { + const search = page.getByRole("searchbox", { name: /^Search notes/ }); + await search.fill(title); + await search.press("Enter"); +}; test.describe("canvas note panel", () => { // The canvas reads the newest UMAP run, so these tests run one at a time in @@ -98,6 +117,7 @@ test.describe("canvas note panel", () => { }); await openFromRail(page, title); + await holdAutosave(page); await typeIntoEditor(page, " unsaved canvas edit"); await panel(page).getByRole("button", { name: "Close panel" }).click(); @@ -118,14 +138,15 @@ test.describe("canvas note panel", () => { await expect(panel(page)).toBeVisible(); await expect(editor(page)).toContainText("unsaved canvas edit"); - await clickBackdrop(page); + await openFromSearch(page, otherTitle); await expect(discardDialog(page)).toBeVisible(); await discardDialog(page) .getByRole("button", { name: "Discard changes" }) .click(); - await expect(panel(page)).toBeHidden(); + await expect(editor(page)).toContainText(`Body of ${otherTitle}`); - await openFromRail(page, title); + await openFromSearch(page, title); + await expect(editor(page)).toContainText(`Body of ${title}`); await expect(editor(page)).not.toContainText("unsaved canvas edit"); expect(posts, "discarding must not save the edit").toEqual([]); }); @@ -153,9 +174,10 @@ test.describe("canvas note panel", () => { page, }) => { await openFromRail(page, title); + await holdAutosave(page); await typeIntoEditor(page, " saved canvas edit"); - const save = await holdNextServerAction(page, "updateDoc", [noteId]); + const save = await holdNextServerAction(page, "saveDocContent", [noteId]); await panel(page) .getByRole("button", { name: "Save note changes" }) .click(); @@ -169,7 +191,7 @@ test.describe("canvas note panel", () => { await expect(savingDialog(page)).toBeHidden(); await expect(panel(page)).toBeVisible(); - await clickBackdrop(page); + await openFromSearch(page, otherTitle); await expect(savingDialog(page)).toBeVisible(); save.release(); @@ -182,7 +204,8 @@ test.describe("canvas note panel", () => { await expect(discardDialog(page)).toBeHidden(); await expect(panel(page)).toBeHidden(); - await openFromRail(page, title); + // The rail still lists the search above, so reopen through search too. + await openFromSearch(page, title); await expect(editor(page)).toContainText("saved canvas edit"); }); From f029dca7543da0cae5411f417a1c615774ad838c Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sat, 28 Nov 2026 22:17:42 -0500 Subject: [PATCH 2/2] Make the canvas no-save check able to catch a save Without a page route, request.postData() was null for server-action requests, so the check could not fail. Co-Authored-By: Claude Sonnet 5.5 --- app/tests/e2e/canvas-note-panel.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/tests/e2e/canvas-note-panel.spec.ts b/app/tests/e2e/canvas-note-panel.spec.ts index 94a480c6..c005a374 100644 --- a/app/tests/e2e/canvas-note-panel.spec.ts +++ b/app/tests/e2e/canvas-note-panel.spec.ts @@ -107,6 +107,9 @@ test.describe("canvas note panel", () => { }); test("unsaved edits ask before the panel closes", async ({ page }) => { + // In Chromium, `request.postData()` is null for server-action requests + // unless the page has a route, so the no-save check below needs one. + await page.route("**/_server*", (route) => route.continue()); const posts: string[] = []; page.on("request", (request) => { if (request.method() === "POST" && request.url().includes("/_server")) {