Repository navigation
Keep a late layer hand-back from taking the keyboard back from Overview - #431
Merged
Merged
Conversation
…yer closed Radix hands focus back from a timer after a layer closes. Under load that timer ran after the next layer (Overview) opened and closed, and the older hand-back restored its own opener (the Settings button) before Overview could return the keyboard to the terminal. A hand-back now stands down when another layer opened after its own closed. The Overview spec also waits for the sidebar to take the keyboard, which the sidebar does one frame after the list shows.
…closed The close and the open are now recorded in layout effects, whose cleanups run before the layout effects of what the same commit adds, so the order no longer depends on render order or on a passive unmount cleanup.
yansfil
added a commit
that referenced
this pull request
Oct 5, 2026
Related: follows #431, which gave `useReturnFocus` a count of opened layers so a late hand-back cannot take the keyboard from a newer layer. ## Summary Overview's modal closed with its own `onCloseAutoFocus` that called `restoreFocus` on the stored return target with no such guard, so the same race stayed there: Radix hands focus back from a timer, and under load that timer can run after the next layer opened and closed. `DialogContent` now takes `returnFocusTo`, the place the owner names, and `useReturnFocus` accepts it (`named`), so Overview goes through the same opened-layer count as every other layer; Overview's own handler is gone. Focus still sitting inside the dialog's own surface is not read as the operator having moved on; focus anywhere else is. ## Review - **판단해 주세요**: `named` lives on `useReturnFocus` and `returnFocusTo` on `DialogContent` rather than a second hook; `AddProjectDialog` and other `onCloseAutoFocus` users were left as they were. - **조심해서 볼 파일**: `web/src/components/ui/layer.ts` - the hand-back order guard shared by every layer. ## Evidence - **확인한 것**: - 3 unit tests in `web/src/components/ui/layer.test.tsx`, each deciding the order by calling the hand-back itself: the named target is used, a late hand-back after a newer layer opened and closed leaves the keyboard alone, focus outside the layer is kept while focus on its own surface is taken back. - `bash scripts/verify-web.sh` passes (994 and 99 unit tests, typecheck, lint, builds); `overview-modal.spec.ts` 2 of 2 on macOS. - **확인하지 못한 것**: - No Linux or Windows run. - The race itself was not reproduced under load; the tests set the order the timers would produce.
yansfil
added a commit
that referenced
this pull request
Oct 5, 2026
Related: #433 (retried interactions), #437 (Rust sleeps), #430 (guide), #434 (clock injection and Rust waits), #429 (headless renderer), #438 (shared gate), #419 (retries) ## Summary Playwright specs in `web/e2e` and `desktop/e2e` now pass `eslint-plugin-playwright` plus two repository rules, an e2e test size budget runs in the same `lint` script, and clippy refuses `std::thread::sleep` in Rust. All of it runs in the existing lanes (`web lint`, `desktop lint`, `clippy`); no new job or workflow step. Existing violations were fixed where a state exists to wait for, and the rest carry a reasoned allow, listed below. ## Review - **판단해 주세요**: `quietFor` is the only sleep an e2e spec may use for a window in which something must not happen; its 30 call sites each state the claim. Is a time window the right form for those, or should some become a counted check? - **판단해 주세요**: `no-conditional-in-test` (98 hits, mostly `process.platform` and fold toggles) and `max-expects` (2409 hits at the default of 5) are not enabled; the size budget replaces `max-expects`. Enable either? - **조심해서 볼 파일**: `web/eslint-rules/hide-e2e.mjs` - two hand-written rules; `web/scripts/check-e2e-test-size.mjs` - the baseline logic; `web/e2e/wait.ts` - the one `eslint-disable` for `waitForTimeout`. - **조심해서 볼 파일**: `web/e2e/s3.spec.ts` (two draft recovery tests) - they must not reload the page, so they carry a line allow with the reason; adding `about:blank` made both fail. - **조심해서 볼 파일**: `web/e2e/theme.spec.ts` - `networkidle` replaced by asserting hided's empty 404 for `/gallery`; `web/e2e/agent-tab-groups.spec.ts` - a 300 ms sleep between two `tab focus` calls was removed (the CLI returns after Herdr applied it, events reach the core in order; a probe showed the first focus changes nothing visible); `web/e2e/s3.spec.ts` - the offline window now also asserts the file was not written. - **질문**: #434 merged first; this branch took main and dropped the `#437` allows on the five functions it fixed (`hide-ai/src/router.rs` x3, `usage.rs`, `live.rs`). ## Evidence - **확인한 것**: `pnpm lint` in `web` and `desktop` pass (ESLint plus the size budget); `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass; `scripts/tests` 108 pass; the identity and attribution checks pass. - **확인한 것**: each rule fires on a planted violation (`waitForTimeout`, an action inside `toPass`, `goto` of `#token=` after `restart()`); the size budget fails when a baselined test grows (it caught this branch's own 9-line addition to the Overview test, which moved into a helper). - **확인한 것**: ran the changed specs against a local `hided` and the pinned Herdr, all pass: theme (gallery and restart), start-panel, agent-tab-groups external focus, sidebar-pr-start, cmdk recents, both s3 draft recovery tests, s6 Main/Overview (failed once on the first run at the File Views open, passed on the immediate rerun; this PR only relabels a wait in that test), and the Overview graph test. - **확인한 것**: a reviewer found the labels above too loose in a first pass (a settle wait named `quietFor`, native captures without `compositorPresents`, Rust allows with the wrong reason); all were fixed before this PR. - **확인하지 못한 것**: known gaps in the new lint: `expect.soft(fn).toPass()`, a poll that calls an action through a helper, and a `goto` through a local `url` variable after `restart()` are not seen; a hand-written `new Promise((r) => setTimeout(r, ms))` is not seen either (mobile.spec x2, remote-workspace, browser, workspace-columns x2 exist today); clippy covers `std::thread::sleep` only, not `park_timeout`, `wait_timeout` as a delay or a spawned `sleep`. #437 lists the Rust gap. - **확인하지 못한 것**: the other edited specs (digit, keys, browser, terminal-links, session-labels, the macOS desktop specs) were not run; desktop e2e needs the macOS lane. Windows and Linux lanes run in CI. - **확인한 것**: macOS clippy does not compile `cfg(windows)` or Linux-only code, which is how the two Windows named-pipe waits in `hide-platform/src/ipc.rs` slipped through (found by the Windows OS contract job). A source scan of every `sleep(` call in the tree, regardless of cfg, now finds none outside an allowed function; a Windows-target clippy run reached `hide-platform` and `hide-ai` before `ring` failed to build on this Mac, so the Windows lane in CI is the check for the rest. - **확인하지 못한 것**: `Instant::now` and `SystemTime::now` bans in clock-injected modules. Clippy cannot scope a method to a module and #434 has injected no module yet; once it has, a per-crate `clippy.toml` or a module-level `deny` with those two methods is the follow-up. ### Sleeps and waits, before and after | | Before | After | | --- | --- | --- | | `waitForTimeout` in `web/e2e` and `desktop/e2e` | 53 | 1 (`web/e2e/wait.ts`, behind three named helpers) | | `quietFor`: a window in which something must not happen | - | 30 | | `compositorPresents`: native capture on macOS | - | 6 | | `measureFor`: idle measurement and sample pacing | - | 5 | | `animationsFinished`: waits for finite animations, not time | - | 10 | | `unchangedForFrames`: waits until a value stops changing for 30 animation frames (bounded) | - | 3 | | Waits on time removed or replaced by a state or a stronger assertion | - | 3 (agent-tab-groups ordering sleep, `networkidle`, s3 offline window) | | `no-action-in-poll` allows, all #433 | - | 10 | | `reopen-after-restart-through-blank` allows (reconnect is the subject) | - | 2 | | Rust allow (`#[allow(clippy::disallowed_methods)]`) | Count | | --- | --- | | Bounded polling helper or inline bounded poll (sleeps between observations of a state, with a deadline) | 26 | | The sleep is the subject (a slow fake peer or backend) | 1 | | A child process kept alive for the test to kill | 6 | | Production wait, not test code | 31 | | Test that sleeps for a state, tracked in #437 | 59 | The production waits are allowed line by line rather than by a crate-root allow with `deny` in test modules: that form would leave every new `mod tests` and `tests/*.rs` file unguarded until someone adds the attribute, whereas the line allows fail closed. ### Size budget `web/e2e/test-size-baseline.json` (20 tests; #447 split three of them) and `desktop/e2e/test-size-baseline.json` (13) record the tests over 120 lines or 40 `expect` calls as a ceiling that only shrinks. ## Pending guide sentences `docs/TESTING.md` names #429, #438 and #434 as pending, and #419 for retries and nextest; each of those pull requests fixes its own sentence when it takes main. <details><summary>Verification record</summary> Base `origin/main` 4df25a0. Local runs: `pnpm lint` (web, desktop), `scripts/verify-cargo.sh clippy --workspace --all-targets -- -D warnings`, `fmt-check`, `python3 -m unittest discover -s scripts/tests`, Playwright specs listed above. Review by a separate reviewer: see the PR comments. </details> Main merge (#434, #435, #431, #450): baselines were refreshed after it. Two `browser-cdp.spec.ts` tests added by main were already over the budget and are baselined (172 and 121 lines); the Overview test grew 9 lines on main and its ceiling moved with it. Rust allows: 123 in total after the merge.
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.
Summary
Overview를 닫은 뒤 터미널로 키보드가 돌아오지 않던 문제를 고칩니다. nightly macOS의
overview-modal.spec.ts두 실패(:92toBeFocusedinactive,:100sidebar가 focus를 못 가짐)의 원인입니다.화면은 바뀌지 않습니다.
:92제품 결함. Radix는 layer가 닫힌 뒤 timer로 focus를 돌려줍니다. 부하에서는 먼저 닫힌 Settings의 timer가 입력 뒤로 밀려, Overview가 열렸다 닫힌 다음에 실행됩니다.그러면 Settings가 자기 opener(사이드바 버튼)로 focus를 가져가고, Overview의 복귀는 "이미 다른 곳에 focus가 있다"며 건너뜁니다. 로컬에서 focus 이벤트와 호출 스택으로 확인했습니다.
:100spec 결함. 사이드바는 목록이 보인 한 프레임 뒤(requestAnimationFrame)에 focus를 가져가는데, spec이 모달이 사라진 즉시 읽었습니다. 같은 기대를expect.poll로 기다립니다. 기대는 낮추지 않았습니다.useReturnFocus(web/src/components/ui/layer.ts)가 layer 열림 횟수를 세고, 자기가 닫힌 뒤 다른 layer가 열렸으면 focus를 건드리지 않고 물러납니다(preventDefault는 유지).Review
web/src/components/ui/layer.ts- dialog, sheet, alert-dialog, entry-menu 네 곳이 쓰는 hook이라 한 곳의 의미가 바뀝니다. 닫힘과 열림은 layout effect로 기록해 같은 commit에서 교체되는 경우도 "나중에 열림"으로 셉니다.@platform을 달지 않았습니다. 원인(Radix timer와 CPU 부하, rAF)은 OS가 아니라 브라우저 엔진의 일정이고 macOS에서만 드러난 것은 runner가 느리기 때문입니다. Linuxweb-e2e가 같은 경로를 이미 돌립니다. macOS PR lane은 느려서 오히려 시간만 늘립니다.Overview.tsxonCloseAutoFocus)에는 같은 횟수 확인이 없습니다. 이번 실패에는 닿지 않았고 범위 밖이라 두었습니다.Evidence
yes4개 부하에서 spec이 약 1/10~1/25로 실패했고, 두 실패가 nightly와 같은 줄(:92,:100)이었습니다.overview-modal.spec.ts를 60회(첫 수정) + 30회(최종 head) 돌려 실패 0, retry 0.layer.test.tsx3개. 수정 전 코드에서는 "새 layer가 열렸다 닫힌 뒤 늦게 온 hand-back" 테스트가 실패하고 수정 후 통과합니다.typecheck,lint, unit 949개 통과.sidebar-menus.spec.ts,worktree-removing-menu.spec.ts는 이 shell의 git 서명 agent 실패(Couldn't sign message)로 fixture가 시작하지 못해 돌리지 못했습니다. 이 변경과 무관한 환경 문제입니다.Gallery.tsx처럼 content part를 항상 mount해 두는 호출자는 닫힘을 알 수 없어 이전 동작 그대로입니다(실제 제품 호출자는 모두 열려 있을 때만 mount).@flaky나 격리 표시가 없었고 새로 달지 않았습니다.