Repository navigation
fix(artifacts): ask before an in-app exit drops unsaved artifact edits - #20355
Conversation
A dirty artifact edit buffer now registers with the app shell's leave registry and publishes its stake, so the global sidebar, the command palette, browser Back and a popout's forwarded navigation intent ask before they replace the page. The registry needs a synchronous answer, so the guard refuses the exit and opens the page's own discard dialog; a confirmed discard ends the edit through endEditing, so a save still on the wire cannot raise a stale failure or conflict notice. Split out of #17194 at the reviewers' request. Co-authored-by: Yusheng Xu <buluoray@gmail.com>
UX Review (Opus 5.5) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS After "Discard changes" the user stays on the artifact, so the Settings click looks swallowed and they have to click it again. Watch
Suggestions
[UX-REVIEWED] 0b2fa56 Description read[DESCRIPTION-READ] f2d2507773727653241718278ab106dcf7774feb473c493d43abfe91717ed556 That sha256 names everything this verdict read: the PR description, plus the 7 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check one thing before merge: a refused popout intent such as "Ask agent to address" drops its prefill, so after confirming the discard the user has to click it again in the popout. [DESIGN-REVIEWED] 0b2fa56 Description read[DESCRIPTION-READ] 17c6af52536e6d42f9f60e05df1a0d3d13ec2e688163c836055e1c0c517b97b2 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check before merge: after the user confirms a discard, the navigation does not continue on its own. They have to click again, as What this change shipsInventory (8 items) — 8 justifiedIntent: stop unsaved artifact edits from being lost when the user leaves through the app's own navigation. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 0b2fa56 Description read[DESCRIPTION-READ] 10d07efeb863167a11be57b5cea67fab41a406a305c5e4a6ff6c2ea39ab03ed4 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
The desktop app's menu entries and the Companion's Open session called applyNavIntentInMain without a leave check, and a bare navigate for other paths, so they replaced the page without asking. Both now run the shell's leave check, and mayLeave is a required argument so a caller cannot skip it by omission. Co-authored-by: Yusheng Xu <buluoray@gmail.com>
|
🤖 Kiro Crew Auto-Pipeline [operator: buluoray#20355]: Dispositions for the reviews on a9d84de, addressed at 0b2fa56.
|
|
🤖 Kiro Crew Auto-Pipeline [operator: buluoray#20355]: Dispositions for UX Review CONCERNS (advisory) on 0b2fa56. No push for these: a push would restart every lane on this head, and none of them is a defect in what the PR claims.
|
mbriones98
left a comment
There was a problem hiding this comment.
Checks green and readiness passed at 0b2fa56; no behavior change.
Problem / Motivation
Goal: Unsaved edits on an artifact are not lost when the user leaves the page through the app's own navigation.
While an artifact is open in the editor with unsaved changes, clicking a sidebar entry, running a command-palette jump, pressing the browser's Back button, or following a navigation forwarded from a popped-out artifact window replaces the page at once. The edits are gone with no prompt. Only a real unload (closing the tab, reloading) asks, through
beforeunload, because client-side route changes never fire it.Why it matters
Editing an artifact by hand is the one place on the page where the user's own typing is at stake. A stray sidebar click or Back press silently throws that work away, and nothing on screen says it happened.
Not a goal
What changed (motivation → approach → change)
useMayLeaveForNavigation), but the artifact detail page never registered with it, so a dirty edit buffer answered "may leave" by default.ArtifactDetailPageregisters a guard (useRegisterNavigationLeaveGuard) and publishes its stake (usePublishNavigationStake(dirty)), so the sidebar, command palette and browser Back ask first. The registry needs a synchronous answer, so a dirty buffer refuses the exit and opens the page's own async discard dialog (useConfirm, notwindow.confirm, whichwindowConfirmRatchetcaps). A second ask while the dialog is up shows one dialog. A confirmed discard callsendEditing(), as Cancel does, so a save still on the wire cannot raise a failure or conflict notice for the buffer that is gone.applyNavIntentInMaintakes an optionalmayLeavecheck, andApp.tsxpasses the shell's leave answer. A refusal drops the whole intent: no prefill is staged, no slot switches, nothing navigates. The window is raised before the check so its confirm appears on a window the user can see. The App-level variable is renamed frommayLeaveForErrorHandofftomayLeaveForNavigation, since it now serves both callers.subscribeNativeNavigate) run the same leave check before they navigate.mayLeaveis now a required argument ofapplyNavIntentInMain, so no caller can skip the check by leaving it out.NavigationLeaveGuard.tsxlists the forwarded intent among the wired exits;docs/system-specs/modules/artifacts.mddocuments the guard.This is the edit-buffer leave guard split out of #17194 at the reviewers' request, so it can be reviewed and land on its own.
Backwards compatibility
Compatible: frontend-only; no API, stored data or config change.
applyNavIntentInMain's newmayLeavedependency is required; both in-tree callers pass it.Removes nothing: the change only adds a confirm step in front of existing navigations; every exit still works once the buffer is clean or the discard is confirmed.
Tests
ArtifactDetailPage.leaveGuard.test.tsx(new): with a dirty buffer the shell's leave check refuses and opens the app discard dialog (nowindow.confirm; a repeated ask still shows one dialog); discarding lets the repeated navigation leave; cancelling keeps the edit; a clean buffer leaves without asking; a save in flight at the discard shows no failure notice afterwards. Making the guard always return true reddens three of the four.App.navLeaveGuard.test.tsx: a popout-forwarded intent asks the page on screen, keeps the draft on a declined confirm and navigates on an accepted one. WiringmayLeaveto always-true reddens the declined case. A native menu path and a native session deep link likewise keep the draft on a declined confirm and navigate on an accepted one; removing the native check reddens both declined cases.popoutNavForwarding.test.ts: a refused leave drops the intent (no prefill, no slot switch, no navigate); an allowed one navigates. Removing the veto check reddens both.Manual verification
Local:
tsc,eslint --max-warnings=0on the changed files,docs-lint.sh, the comment-history and brand gates, and 71 related frontend test files (801 tests: ArtifactDetailPage, App, navIntent, popout, NavigationLeave) pass.local-gate.py's backend half was stopped at its time budget; this diff touches no backend file, so CI runs it.Screenshots / video
Real built SPA, API stubbed, dark theme. A Settings sidebar click with a dirty buffer: the page stays put and its own dialog asks (no native confirm fired).
• unsaved changesin the footer):Related Issues
Split from #17194.
Pattern harvest
Rule candidate: review-prompt
Pattern: an optional veto callback (
mayLeave?: () => boolean) lets a navigation caller skip the leave check by omission; make the check a required argument so every exit decides.