Move focus into a new settings draft in the same commit - #1968
Merged
Merged
Conversation
Copying settings, loading previous global settings and switching to auto-discovery remount the form, then focused its first field in the next animation frame. A keystroke typed before that frame went to the old target, and one typed as the frame fired could land in the newly focused field instead. Focus now moves in a layout effect, during the commit that mounts the form.
PR Summary by QodoFocus new settings drafts before the next animation frame
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent |
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
Copying settings from another cluster, loading previous global settings, or choosing auto-discovery now moves focus into the new form immediately, instead of one animation frame later. This fixes the settings e2e test that flaked: "copy into an unconfigured cluster saves edited headers without an intermediate write".
What happened
Each of those three actions remounts the integration form, which holds the header edits, and then focuses the form's first field, the backend URL. The focus ran in
requestAnimationFrame, so there was a gap between the remount and the focus move.Playwright's
fill()has two steps: it focuses the target field, then types into whatever has focus. Under load, the delayed frame could fire between those steps. In the test that meant:fill('new-tenant')focuses theX-Scope-OrgIDvalue field.fill()of the URL.headers: []. The header was never edited, so the form has no header operations.That is the exact failure the test showed. Holding the app's animation-frame callbacks and releasing them when the header field gains focus reproduces it every time.
A real user is unlikely to type within one frame. But on a loaded machine, keystrokes typed right after choosing a source could go to the closed picker or the wrong field.
What changed
LocalConnectionSettingsmoves focus in a layout effect, which runs during the commit that mounts the new form, before any later input event is handled. The three call sites hand it a focus function instead of scheduling a frame.The two other
requestAnimationFramefocus calls in Settings are unchanged. They move focus to a heading after navigation, and nothing types into the form after them.Testing
npm run test:e2e:settings: 135/135, at load average ~200. Settings vitest 38/38.make tscclean.Note
Low Risk
UI-only focus timing in settings; no auth, API, or persistence changes beyond fixing mis-targeted typing after draft remounts.
Overview
Fixes a focus timing race when local connection settings remount the draft form after copy from another cluster, load previous global settings, or switch to auto-discovery.
LocalConnectionSettingsno longer schedules the first-field focus withrequestAnimationFrame. It stores a focus callback infocusAfterDraftand runs it in auseLayoutEffect, so focus moves in the same commit as the new form—before later input events can steal keystrokes.The flaky e2e "copy into an unconfigured cluster saves edited headers without an intermediate write" now asserts that Metrics backend URL is focused immediately after picking a copy source (before the next frame), matching the new behavior.
Reviewed by Cursor Bugbot for commit 347f132. Bugbot is set up for automated code reviews on this repo. Configure here.