Skip to content

Commit 1eb3b3b

Browse files
author
Carl
committed
Let the destination's mount focus win over the Retry handoff
Signed-off-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
1 parent 9b4572d commit 1eb3b3b

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎src/app/App.tsx‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ import { AgentsContext } from "../features/agents/react";
77
import { ToastProvider } from "../shared/design-system/ui/Toast";
88
import { Button } from "../shared/design-system/ui/Button";
99
import { UpdateNotice } from "../features/updates/UpdateNotice";
10-
import {
11-
useEffect,
12-
useLayoutEffect,
13-
useRef,
14-
useSyncExternalStore,
15-
} from "react";
10+
import { useEffect, useRef, useSyncExternalStore } from "react";
1611
import { registerAppShortcuts } from "./shortcuts";
1712
import type { AppServices } from "./services";
1813
import { Settings } from "./Settings";
@@ -86,7 +81,9 @@ function ConnectedApp({ services }: { services: AppServices }) {
8681
const restoring = client.status === "loading" || !!connection.restoring;
8782
const settings = route.target.kind === "settings";
8883
const retryFocus = useRef<string | undefined>(undefined);
89-
useLayoutEffect(() => {
84+
// A passive effect runs after the destination's own mount focus, so this
85+
// only fills in when focus would otherwise be left on the body.
86+
useEffect(() => {
9087
if (!retryFocus.current) return;
9188
if (retryFocus.current === route.state.attempt.id && !settings && restoring)
9289
return;
@@ -276,12 +273,13 @@ function ConnectedApp({ services }: { services: AppServices }) {
276273
onClick={(event) => {
277274
const focused =
278275
event.currentTarget === document.activeElement;
276+
const before = services.navigation.snapshot().attempt.id;
279277
route.retry();
280278
// Retry can remove this control and briefly unmount the
281279
// shell; hand focus to main only once it has fallen away.
282-
retryFocus.current = focused
283-
? services.navigation.snapshot().attempt.id
284-
: undefined;
280+
const after = services.navigation.snapshot().attempt.id;
281+
retryFocus.current =
282+
focused && after !== before ? after : undefined;
285283
}}
286284
>
287285
Retry navigation

0 commit comments

Comments
 (0)