Skip to content

fix(files): keep Escape closing Files when the key re-renders the app - #3026

Merged
devswha merged 4 commits into
mainfrom
fix/files-escape-2631
Nov 5, 2026
Merged

devswha merged 4 commits into
mainfrom
fix/files-escape-2631

Conversation

@devswha

@devswha devswha commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Fixes #2631

Cause

The files-prompt-regression.ts Escape 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 reached window in the capture and bubble phases, focus was on body, no file viewer, diff or native modal was open, and Files stayed open.

A local run with an init script that logs every window keydown listener add, remove and call showed what happened in the stuck rounds:

  1. useSplitView's bubble listener cancel (registered at startup, so before FilesDialog's) runs first and calls clearDropPreview(), which sets paneDragging and dropAt state.
  2. When React does not bail out of that set, the microtask after that listener renders App before the next listener runs.
  3. FilesDialog's onClose is an inline arrow in App, so its effect ([onClose, viewing, docked]) removes its window listener and adds a new one during that render.
  4. A listener removed during dispatch is skipped, and one added during it is not called, so FilesDialog never sees that Escape.

In the log: FilesDialog's listener was attached at 1430.9 ms, cancel ran 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

  • FilesDialog reads its latest props (onClose, docked) through useEffectEvent. Its window listener now changes only with viewing, so a render inside the same key press no longer swaps it out.
  • With the listener in place, Files also stands down when the focus is in another modal, and when another dialog already took the key (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 pane dragstart shows the split guide, so the next Escape's clearDropPreview is 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.ts failed at that step (.files-dialog still 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 fast on 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.

devswha and others added 2 commits November 6, 2026 01:27
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]>
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between acb94eb and b7d3e06.

Files selected for processing: 3

  • changelog.d/files-escape-after-pane-switch.md
  • scripts/files-prompt-regression.ts
  • src/components/FilesDialog.tsx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

devswha and others added 2 commits November 6, 2026 01:59
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]>
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
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.

@devswha
devswha merged commit f2bbee9 into main Nov 5, 2026
13 checks passed
@devswha
devswha deleted the fix/files-escape-2631 branch November 5, 2026 17:37
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.
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.

Files: Escape may be ignored right after a pane switch (seen once on CI, not reproduced)

1 participant