From f07c0903c5dafaebc61dfc9a1f3e38cc8870e9d9 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 6 Nov 2026 15:18:15 +0000 Subject: [PATCH 1/2] fix(ui-react): focus the stale-apply banner after it renders (#3657) On a stale apply the media card set the banner in a passive effect and focused it on the next animation frame. Under load that frame can run before React commits the banner, so the focus found no element and stayed on the destination input. The banner now takes focus in an effect that runs after the commit that mounts it. The layout test's teardown released no held plans before stopping the fixture. Stop drains every forwarded request, so a failure while the re-preview was held waited on that request until Node's fetch timed out, which turned a one-second assertion into a 30 s hook timeout with no detail. Teardown now releases held plans first. Co-Authored-By: Claude Opus 5.5 --- .../ui-react/src/components/activity/hygiene-media.tsx | 9 ++++++++- packages/ui-react/tests/browser/hygiene-media.layout.tsx | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/ui-react/src/components/activity/hygiene-media.tsx b/packages/ui-react/src/components/activity/hygiene-media.tsx index 41ed9f1b5f..56d2df273c 100644 --- a/packages/ui-react/src/components/activity/hygiene-media.tsx +++ b/packages/ui-react/src/components/activity/hygiene-media.tsx @@ -316,6 +316,8 @@ export function MediaFinding({ item, controller: c }: { item: InboxActionItem; c const [texts, setTexts] = useState>>({}); const [preview, setPreview] = useState(null); const [banner, setBanner] = useState(null); + /** Counts stale applies; each one focuses the banner once it has rendered. */ + const [bannerFocus, setBannerFocus] = useState(0); const [filesOpen, setFilesOpen] = useState(false); const latest = useRef(null); const aborter = useRef(null); @@ -414,12 +416,17 @@ export function MediaFinding({ item, controller: c }: { item: InboxActionItem; c handled.current = item.version; if (outcome.status === "stale" && row) { setBanner(outcome.reason === "stale-approval" ? refusalText({ code: "stale-approval" }) : "Changed since the preview. Updated below. Check it before applying."); + setBannerFocus((n) => n + 1); void run(row, texts[row] ?? ""); - requestAnimationFrame(() => bannerRef.current?.focus()); } else if (receipt?.outcome === "partial") requestAnimationFrame(() => showFiles.current?.focus()); else requestAnimationFrame(() => recoveryRef.current?.focus()); // eslint-disable-next-line react-hooks/exhaustive-deps }, [item.version]); + // The banner is state set just above, so it mounts in a later commit than this card's + // outcome: focus it after that commit, never on a frame that may come first (#3657). + useEffect(() => { + if (bannerFocus > 0) bannerRef.current?.focus(); + }, [bannerFocus]); const current = preview?.state === "done" && row !== null && preview.row === row && preview.text === text ? preview : null; const replicatedPlan = row ? planFor(options.get(row), row, text) : null; diff --git a/packages/ui-react/tests/browser/hygiene-media.layout.tsx b/packages/ui-react/tests/browser/hygiene-media.layout.tsx index 3802825b5e..d7934c9117 100644 --- a/packages/ui-react/tests/browser/hygiene-media.layout.tsx +++ b/packages/ui-react/tests/browser/hygiene-media.layout.tsx @@ -39,7 +39,12 @@ afterEach(async () => { u?.dispose(); s?.close(); h?.remove(); - if (f) await commands.hygieneServer({ op: "stop", id: f.id }); + if (f) { + // Stop drains every forwarded request, so a failure while a plan is held must release it first, + // or the drain waits on the held preview until Node's fetch times out (#3657). + try { await commands.hygieneServer({ op: "set", id: f.id, patch: { releasePlans: true } }); } + finally { await commands.hygieneServer({ op: "stop", id: f.id }); } + } if (originalTheme === undefined) delete document.documentElement.dataset.theme; else document.documentElement.dataset.theme = originalTheme; }); @@ -318,7 +323,7 @@ test("dark 320: a preview that throws is a 409 the card states, and nothing was await radio("Move to a final location").click(); await destination("places/throw.png"); // A 409 with no newer Action states its failure only after the card's one-second wait for a - // newer version (`newerThan`, packages/ui-react/src/components/activity/hygiene-media.tsx:341-348), + // newer version (`newerThan`, packages/ui-react/src/components/activity/hygiene-media.tsx:343-350), // so the default one-second poll races that window. Allow the wait plus the request. await expect.poll(() => alertText(), { timeout: 5000 }).toBe("Couldn't prepare a preview. Nothing was changed."); expect(page.getByRole("button", { name: "Try again", exact: true }).query()).not.toBeNull(); From 9f1b673256098e096051d720d5f815d52c00b55d Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 6 Nov 2026 15:18:57 +0000 Subject: [PATCH 2/2] chore(changeset): note the stale-apply banner focus fix (#3657) Co-Authored-By: Claude Opus 5.5 --- .changeset/media-stale-banner-focus.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/media-stale-banner-focus.md diff --git a/.changeset/media-stale-banner-focus.md b/.changeset/media-stale-banner-focus.md new file mode 100644 index 0000000000..2be39a554b --- /dev/null +++ b/.changeset/media-stale-banner-focus.md @@ -0,0 +1,5 @@ +--- +"@schlessera/brain-ui-react": patch +--- + +On a stale apply, the media review card's "Changed since the preview" banner now reliably takes focus. Before, a slow frame could leave focus on the destination field.