Skip to content

Keep a control's focus when the settings dialog opens - #20

Merged
joowon-jang merged 1 commit into
mainfrom
fix/model-settings-focus-flake
Oct 6, 2026
Merged

joowon-jang merged 1 commit into
mainfrom
fix/model-settings-focus-flake

Conversation

@joowon-jang

Copy link
Copy Markdown
Collaborator

Fixes the intermittent ModelSettingsDialog CI failure seen on PR #18 ("Expected element with focus: <input …ctx_size>, Received: <h2 …-title>").

Cause: on open the dialog schedules requestAnimationFrame(() => heading.focus()). If a control is focused before that frame — the test focuses ctx_size as soon as the first estimate renders, which sometimes happens within the first frame — the late callback steals focus. The same race applies to a user who focuses a control within the first frame.

Fix: remember the focused element after showModal() and move focus to the heading only if it is unchanged at the frame; cancel the frame when the dialog closes.

Verification: a new test (heading focused when untouched; a control focused before the frame keeps focus) failed deterministically before the fix with the CI error and passes after it. Local: lint, typecheck, 1,455 frontend tests, and the affected tests repeated.

🤖 Generated with Claude Code

The model settings dialog moves focus to its heading on the frame after it
opens. When a control was focused before that frame, the late callback took
focus away from it. This made "refreshes resource estimates..." fail
intermittently in CI ("Received element with focus: <h2>") whenever the
estimate appeared before the frame. Move focus only if it has not changed
since opening, and cancel the frame when the dialog closes. A new test
covers both the untouched heading focus and a control focused first; before
the fix it failed deterministically with the CI error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joowon-jang
joowon-jang merged commit e1eb07e into main Oct 6, 2026
5 checks passed
@joowon-jang joowon-jang mentioned this pull request Oct 6, 2026
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.

1 participant