Repository navigation
Ask before closing a Workspace tab with unsaved edits - #408
Merged
abhishekgahlot2 merged 2 commits intoNov 5, 2026
Merged
abhishekgahlot2 merged 2 commits into
abhishekgahlot2 merged 2 commits into
Conversation
Cancel now answers while a save runs, so a save that never returns no longer traps the page, and a save that ends after Cancel leaves the tab alone. Autosave pauses for the tab whose close question is open, so Discard never closes a tab whose edits were already stored and a background conflict cannot swap the text behind the dialog. Tests now mount the real WorkspacePane over a stubbed backend.
Contributor
|
Merged, thanks @coolestnick. Asking before an unsaved tab closes was a real gap. I added a follow-up commit so Cancel works while a save is running and autosave pauses while the question is open. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #342
Closing a Workspace file tab threw away edits that were not saved yet: anything typed in the 800 ms before autosave, or left after a failed save.
closeWorkpieceremoved the tab without reading its dirty state, and unmounting the editor cleared its autosave timer.What changed
ModalandButton(the archive-bot dialog's recipe).How
components/chat/workpiece-close.ts: the close decision as a small pure function, as the issue asked: close, or ask.components/chat/workpiece-close-guard.tsx: a hook that runs the close for the tab strip and owns the dialog. Each mounted editor registersdirty()andsave()under its tab id.session-view.tsxis unchanged (it is at its file-size baseline).workspace-pane.tsx: the editor registers itself; the tab strip's close goes through the guard.artifact-editor-state.ts:save()now resolvestruewhen the edits are stored andfalsewhen they are not (an error, a 409 conflict, an invalid state). Its two existing callers ignore the result, so they behave as before.Edge cases handled:
Screenshots
From the real app against a local backend and database. Same thread, same steps: open
Launch notes.docx, type, close the tab straight away.Before (main): the tab closes at once with no question; no save is sent and the edit is lost (the stored revision does not change).
After: the tab asks first.
After, a save that fails (network cut): the tab stays open with the edit, "Unsaved changes" and the error.
After, on a phone (390 px), inside the side panel dialog:
Testing
In the app, against a local backend and Postgres, with the result of each step read back from the database:
PATCH .../workpiece(200), tab closes, the edit is storedPATCH, the edit is not storedThe same steps on main close the tab with no save.
Tests:
frontend/components/chat/workpiece-close.test.tsx, 10 tests:Putting the old behaviour back fails 4 of them, and removing each guard fails its own test. The tests answer through the guard's
choose, which the dialog buttons call, because two other test files load the dialog library before a DOM exists, so its portal cannot mount in the full suite.Checks:
bun run typecheck: passes;frontend/,bun run test: 1856 pass, 0 fail;bun run lint: nothing in the changed files;bun run build: passes;bun test scripts/agent-docs.test.ts: passes.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.