Skip to content

Prompt to save on window close after a cancelled quit - #18820

Merged
gtritchie merged 6 commits into
mainfrom
bugfix/18818-cancelled-quit-disarms-close
Sep 15, 2026
Merged

gtritchie merged 6 commits into
mainfrom
bugfix/18818-cancelled-quit-disarms-close

Conversation

@gtritchie

@gtritchie gtritchie commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Intent

Fixes #18818.

On RStudio Desktop, cancelling the quit that a window close triggers left the window's close button disarmed for the rest of the session: later closes exited immediately, with no prompt for unsaved documents and no workspace save.

MainWindow.closeEvent() set quitConfirmed = true as soon as desktopHooks.quitR() returned. quitR() is void and only dispatches the quit sequence — the promise resolves while the save prompts are still on screen, so the flag was set whatever the user answered. Nothing cleared it except a session restart, which is why a morning cancel persisted all afternoon.

The assignment was also redundant: on a confirmed quit, GWT sets PENDING_QUIT_AND_EXIT and the session exits, SessionLauncher.onRSessionExited() calls MainWindow.quit(), and quit() sets quitConfirmed = true before window.close(). This change drops the assignment in closeEvent() and leaves quit() as the sole setter.

closeEvent() held a second piece of state with the same problem. It recorded the window bounds on the first close attempt and set geometrySaved so later attempts skipped it, so cancelling froze the saved geometry at the cancel-time bounds and every move or resize for the rest of the session was discarded. The bounds are now saved in the branch that lets the window close, which is the only point where the geometry is final, and the flag is gone.

Desktop only. quitConfirmed has no server-side counterpart, and closing a browser tab in Server mode is not a quit.

Approach

  • src/node/desktop/src/main/main-window.ts: remove the .then() that confirmed the quit on dispatch; move the saveWindowBounds() call into the closing branch and delete geometrySaved along with its reset in onWorkbenchInitialized().
  • src/node/desktop/test/unit/main/main-window.test.ts: four cases in the style of the existing crashed-renderer fake — a closeEvent whose quitR() resolves leaves quitConfirmed false; a second closeEvent still calls preventDefault() and re-runs quitR(); the closing pass saves the current bounds; the cancellable pass saves nothing. The options singleton is pointed at a temp directory so no test touches the real user config.

The close-after-confirmed-quit routes were checked: onSessionQuit(), onRSessionExited() (PendingQuitAndExit), the launchSession() failure dialog, and runDiagnostics all go through quit(), which closes the window and so reaches the geometry save. SessionLauncher.onLaunchError() closes the window directly but is covered by the existing !this.sessionProcess || exitCode !== null guard, and by the !!window.desktopHooks probe when an error page is loaded.

Two consequences worth naming. Clicking the close button repeatedly while the save prompt is up now dispatches the quit sequence again instead of closing the window, because the main process is never told whether a quit was cancelled or is still being answered. Suppressing that would need a signal ApplicationQuit does not send — it abandons a quit at seven independent exits with no common funnel — and a pending flag without one would leave the close button dead, which is the same bug in a less visible form. Stacked prompts also replace what used to happen on that second click: the window closed with the prompt still on screen. Separately, geometry is no longer persisted for a cancelled close, so a session that is cancelled and then hard-killed keeps its previous bounds rather than the cancel-time ones.

QA Notes

Open RStudio Desktop, click the window close button, cancel the prompt. Create a variable in the console and edit an open document, then click close again: the unsaved-documents and save-workspace prompts appear, and confirming writes .RData. Before this change the second close exited silently.

For the geometry half: cancel a close, then move and resize the window, then quit and restart. The window comes back where it was left, not where it sat when the close was cancelled.

cd src/node/desktop && npm test && npm run lint && npm run typecheck

closeEvent() set quitConfirmed as soon as desktopHooks.quitR() returned,
but quitR() only dispatches the quit sequence -- it resolves while the
save prompts are still on screen. Cancelling left the flag set for the
life of the session, so every later click of the window close button
skipped the quit sequence entirely: no prompt for unsaved documents, and
no workspace save.

quit() already sets quitConfirmed on the confirmed-quit path, before it
closes the window, so let it be the sole setter.

Addresses #18818
@gtritchie gtritchie added this to the 2026.10 (Blue Mistflower) milestone Sep 14, 2026
The main process is never told whether a quit was cancelled or is still
awaiting an answer, so closing again re-runs the quit sequence. Record
that this is deliberate: suppressing the re-run would need a signal that
ApplicationQuit's several cancel exits do not send, and a pending flag
without one would leave the close button dead instead.

Addresses #18818
closeEvent() recorded the window bounds on the first close attempt and
set geometrySaved so later attempts skipped it. Cancelling that quit
therefore froze the saved geometry at the cancel-time bounds, and every
move or resize for the rest of the session was discarded.

Save the bounds in the branch that lets the window close instead, which
is the only point where the geometry is final, and drop the flag: the
single remaining call site needs no guard, since that branch runs once
per window.

Addresses #18818
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
2976 0 187 4
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 746 0 38 3
✅ desktop-macos 755 0 33 0
✅ desktop-windows 750 0 42 1
✅ server-linux 695 0 44 0
✅ setup 28 0 20 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 772c22c23f1883ff800f0ee35cfea28390140f14 - Run #1019

@kevinushey

Copy link
Copy Markdown
Collaborator

LGTM

@gtritchie
gtritchie merged commit 5da3d76 into main Sep 15, 2026
1 of 7 checks passed
@gtritchie
gtritchie deleted the bugfix/18818-cancelled-quit-disarms-close branch September 15, 2026 15:01
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:19 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:19 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:20 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:20 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:24 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:24 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:29 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:29 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:29 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:29 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:29 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 15, 2026 15:29 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
e2e-playwright — 772c22c2 Deployed Sep 15, 2026 by gtritchie via windows / e2e-desktop-windows (1) #1019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No question about saving the code and session when exiting the program

2 participants