Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(models): move focus to a route's destination after the dialog's close commits (#2816)

Call White71a262b89044
diff --git a/ui/src/components/settings/models/SettingsModelsPage.tsx b/ui/src/components/settings/models/SettingsModelsPage.tsx
index 47722a7bd..cf6e94a35 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.tsx
@@ -1227,20 +1227,35 @@ export const SettingsModelsPage: React.FC = () => {
read: chains[modelChainKey(routeTarget.agent.backend, routeTarget.modelId)],
available: supplyRead.kind !== 'ready' || currentRouteAgent !== null,
} : null;
+ // Focus moves to the route's destination only after the commit that closed the
+ // dialog asking for it. A close that comes from an effect or a promise renders
+ // later than a frame can fire, and a frame that fires first focuses into a dialog
+ // still trapping focus, which then unmounts and drops focus on the body.
+ const routeFocusRequestRef = React.useRef<{ target: RouteTarget; preserveCurrentFocus: boolean } | null>(null);
+ const [routeFocusEpoch, setRouteFocusEpoch] = React.useState(0);
const focusRouteDestination = React.useCallback((
target: RouteTarget,
preserveCurrentFocus = false,
) => {
- requestAnimationFrame(() => {
+ routeFocusRequestRef.current = { target, preserveCurrentFocus };
+ setRouteFocusEpoch((epoch) => epoch + 1);
+ }, []);
+ React.useEffect(() => {
+ const request = routeFocusRequestRef.current;
+ if (!request) return;
+ routeFocusRequestRef.current = null;
+ const frame = requestAnimationFrame(() => {
focusModelHubProjection({
root: pageRef.current,
- activeTarget: target.opener,
- backend: target.agent.backend,
- modelId: target.modelId,
- preserveCurrentFocus,
+ activeTarget: request.target.opener,
+ backend: request.target.agent.backend,
+ modelId: request.target.modelId,
+ preserveCurrentFocus: request.preserveCurrentFocus,
});
});
- }, []);
+ // A newer request, or leaving the page, supersedes this one.
+ return () => cancelAnimationFrame(frame);
+ }, [routeFocusEpoch]);
const refocusPendingRouteDestination = React.useCallback(() => {
const report = routeCommitStatusRef.current?.report;
if (!report || !pendingRouteOpenersRef.current.has(report)) return;