Repository navigation
fix(files): keep Escape closing Files when the key re-renders the app - #3026
Merged
Merged
Conversation
The split guide's Escape listener (useSplitView) can re-render App in the same key press. FilesDialog re-subscribed its window keydown listener on every render (its onClose is an inline arrow), so that render removed the listener mid-dispatch and the browser skipped it: Escape left Files open. The listener now reads the latest props through useEffectEvent and changes only with `viewing`. Fixes #2631 Co-authored-by: sisyphus-dev-ai <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Review round for #3026. With the listener no longer swapped out, one Escape closed both Files and Settings when Settings was opened with Files open; main closed only Settings, by the same accident this PR removes. Files now stands down while the focus is in another modal, and when another dialog already took the key (preventDefault), so each Escape closes one dialog, as main did in both orders. Co-authored-by: sisyphus-dev-ai <[email protected]>
Owner
Author
|
Merge note: GitHub required checks green at this head, omo CLEAR at this head, threads resolved, merges cleanly. The files-prompt Escape flake was a product bug (Escape lost while the key re-rendered the app and its window keydown listener was briefly re-attached); caught 5 times on CI since #2632. Fixes #2631. |
This was referenced Nov 5, 2026
devswha
added a commit
that referenced
this pull request
Nov 5, 2026
Follow-up to #3026 (#2631). ## Problem #3026 keeps Files' window Escape listener in place across renders. Before that, the listener swap was what made one Escape close only one of two stacked dialogs. Codex's re-review of #3026 at b7d3e06 found one more case where one Escape now closes two dialogs, and it reproduces: 1. Open Files. 2. Open Settings with its shortcut. 3. Click inside Files. Files is drawn above Settings (same layer, later in the DOM), so the click gives Files the keyboard. 4. Press Escape once. Files closes, marks the key handled (`preventDefault`), and then Settings' bubble listener closes Settings as well. Before #3026, only one of them closed. ## Change - `SettingsDialog`'s Escape listener skips an Escape another dialog already took (`event.defaultPrevented`), as Files does since #3026. Each Escape closes one dialog. - `files-prompt-regression.ts` (desktop): opens Files, then Settings, clicks Files' Browse tab, and checks that one Escape closes Files and leaves Settings open, and that the next one closes Settings. No changelog fragment: this fixes behaviour that #3026 introduced and that has not been released. ## Validation - Failing first: with main's `SettingsDialog.tsx`, `bun run check run --build bun scripts/files-prompt-regression.ts` fails at the new step ("one Escape closed both Files and Settings"). With the fix, 8/8 scenarios pass. - `bun run check fast` on 3ddad3d (merged with main): success (typecheck, build, 12235 unit tests, 0 failures); `files-prompt-regression` 8/8 there too. An earlier run had one unrelated timeout (`server/claude-store.test.ts`, 60 s under the parallel run); that file passes 3/3 alone. - Browser regressions that press Escape in Settings, run on this change before it moved to its own branch (same two-file diff on top of #3026's head): `agent-groups-demo`, `agent-lock-demo`, `cliproxy-settings`, `file-text-size-demo`, `file-viewer`, `hide-pc-demo`, `key-bar-customization-demo`, `pane-mute-demo`, `preferences-sync`, `relay-panel`, `settings-pages-demo`, `shortcut-exact-modifiers-demo`, `sidebar-declutter-demo`, `sidebar-split-access-demo`, `usage`, `ui-regression`, all passing. `device-security-demo-regression` fails on a pill/button height layout assertion at 390 px, and fails the same way on origin/main 0df1012 ("Cancel: 43.99 px tall"), so it is unrelated. - Skipped: `bun run check full`, Windows VM, Mac. Co-authored-by: sisyphus-dev-ai <[email protected]>
devswha
added a commit
that referenced
this pull request
Nov 5, 2026
) Fixes #3037. Follow-up to #3036. ## Problem Settings, Files and New workspace each close on their own `window` or `document` Escape listener. Those run in the order they were added, not in the order the dialogs are drawn, so with two dialogs open one Escape could close the dialog underneath and leave the one in front (the one with the keyboard) open: 1. Settings open, then the palette's Browse files: Files opens over Settings and takes the focus. Escape closed Settings and left Files open (reproduced, as in the issue). 2. New workspace open, then Settings with its shortcut: New workspace's `document` listener runs before Settings' `window` listener, so Escape closed New workspace and left Settings open. The issue had this from code reading only; it reproduces (the new regression step fails without the New workspace change). While a workspace was being created, it also took that Escape without closing. ## Change - `focusInOtherModal(surface)` in `src/lib/useFocusTrap.ts`: the focus is inside another `aria-modal` surface. It is the check `FilesDialog` has done inline since #3026; Files now calls the helper. - `SettingsDialog` and `NewSessionDialog` leave an Escape to the dialog that has the focus. Each Escape closes the dialog in front, and the one underneath closes on the next Escape. This follows the WAI-ARIA modal dialog pattern that the Codex and Claude desktop apps also follow: Escape belongs to the dialog that has the focus. Every dialog opened inside Settings (Confirm, Connect phone, usage sign-in, row menus) already handles its own Escape and stops it, so none of them depended on Settings closing. ## Validation - Failing first: `bun run check run --build bun scripts/files-prompt-regression.ts` with two new desktop steps (Files from the palette over Settings; Settings over New workspace). On origin/main the first step fails ("waiting for .files-dialog to be hidden"). With only the New workspace change removed, the second step fails (Settings stays open because New workspace closed instead). With the fix, 8/8 scenarios pass, also after rebasing on origin/main 02881f0. - `bun run check fast` on the rebased head: success (typecheck, build, 12289 unit tests, 0 failures). - Browser regressions, run in the CI runner image (`herdr-ci-runner:local`, `ci-browser-parallel.ts`, 6 workers) on the change before the rebase: 157/160 passed. I re-ran the 3 that failed side by side on origin/main 5b51cbe and on this change, in the same image: `ui-contexts-regression` and `revision-bound-update-demo-regression` pass on both (the first failures came from host load and a checkout whose git directory the container could not read). `unconfirmed-input-demo-regression` fails on both at the same line (`:64`, the terminal textarea wait), so it was already failing before this change. - `bun test scripts/changelog-fold.test.ts`: pass. - Skipped: `bun run check full`, Windows VM, Mac.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2631
Cause
The
files-prompt-regression.tsEscape flake is a product bug. The diagnostics added in #2632 caught it 5 times on CI since then (runs 41935003970, 41942082835, 41959283541, 41980051339, 41985349024). Every time, the Escape reachedwindowin the capture and bubble phases, focus was onbody, no file viewer, diff or native modal was open, and Files stayed open.A local run with an init script that logs every window
keydownlistener add, remove and call showed what happened in the stuck rounds:useSplitView's bubble listenercancel(registered at startup, so before FilesDialog's) runs first and callsclearDropPreview(), which setspaneDragginganddropAtstate.onCloseis an inline arrow in App, so its effect ([onClose, viewing, docked]) removes its window listener and adds a new one during that render.In the log: FilesDialog's listener was attached at 1430.9 ms,
cancelran at 1542.8 ms, then FilesDialog's listener was removed at 1550.1 ms and re-added at 1550.3 ms, with no call in between.Change
FilesDialogreads its latest props (onClose,docked) throughuseEffectEvent. Its window listener now changes only withviewing, so a render inside the same key press no longer swaps it out.preventDefault). Each Escape closes one dialog, the one holding the keyboard, as main did. Without this, opening Settings with Files open and pressing Escape once closed both (review finding, reproduced).files-prompt-regression.ts(desktop) adds a deterministic step. Files is reopened, and a panedragstartshows the split guide, so the next Escape'sclearDropPreviewis a real state change and always re-renders App inside the key press. Escape must then put away both the guide and Files. A second step opens Settings over Files with its shortcut: one Escape must close Settings alone, the next Files.Validation
Review round (omo + Codex MEDIUM: one Escape closed Files and Settings together). A throwaway probe, 8 rounds per order at 1280 px: main left Files open after one Escape in both orders (Files over Settings, and Settings opened over Files). The first head closed both, 16/16. This head leaves Files open in both orders, 16/16, matching main. The new Settings step fails on the first head ("one Escape closed both Settings and Files") and passes now.
Failing first: with the new step and no product change,
bun run check run --build bun scripts/files-prompt-regression.tsfailed at that step (.files-dialogstill visible after the split guide went away). With the fix, 8/8 scenarios pass.Local stress repro (throwaway, instrumented script, Node PTY host, same flow as the check on fresh pages): 23 stuck out of 98 rounds before the fix, 0 out of 100 after.
bun run check faston the merged head b7d3e06: success (typecheck, build, 12212 unit tests, 0 failures).Browser regressions,
bun run check run(files-prompt on b7d3e06, the rest on the round's commit before the last main merge, which touched FilesDialog only in fix(files): keep the Changes scope across a pane or PC switch again #3028's Changes scope):files-prompt-regression,files-panel-demo-regression,diff-find-demo-regression,diff-line-notes-demo-regression,deep-link-demo-regression,file-viewer-regression,ui-regression, all passing.Skipped:
bun run check full, Windows VM, Mac.No UI change, so no screenshots.