From 5a7bdca4ac89204d3618931c437c4828ddf0d0ae Mon Sep 17 00:00:00 2001 From: Sergey Kozyrenko Date: Fri, 12 Jun 2026 17:40:41 +0700 Subject: [PATCH] fix(webui): re-check focus before stealing it in DetailNavigationSheet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stabilizes a flaky test ("does not yank focus onto a listbox option when filteredItems shrinks"): the rAF that moves roving focus now re-checks document.activeElement before calling focus(), so a focus bounce between the effect's gate check and the next frame no longer steals focus. Provisional: the race only reproduces under JSDOM focus simulation (not in real browsers), so the proper fix likely belongs in the test layer — to be revisited separately. Co-Authored-By: Claude Fable 5 --- .../shared/detail-navigation/detail-navigation-sheet.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/src/components/shared/detail-navigation/detail-navigation-sheet.tsx b/frontend/src/components/shared/detail-navigation/detail-navigation-sheet.tsx index fba58137..001af8d9 100644 --- a/frontend/src/components/shared/detail-navigation/detail-navigation-sheet.tsx +++ b/frontend/src/components/shared/detail-navigation/detail-navigation-sheet.tsx @@ -173,6 +173,11 @@ export function DetailNavigationSheet({ } const id = requestAnimationFrame(() => { + // Focus may have returned to the search input since the effect's gate check. + if (document.activeElement === searchInputRef.current) { + return; + } + const node = buttonRefs.current.get(focusedId); if (!node) {