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(ui): preserve settings origin in data routers (#1803)

Call White2110b9b28bbc
diff --git a/ui/src/components/settings/SettingsOverlayNavigationBoundary.tsx b/ui/src/components/settings/SettingsOverlayNavigationBoundary.tsx
index aad61f97f..397953ab8 100644
--- a/ui/src/components/settings/SettingsOverlayNavigationBoundary.tsx
+++ b/ui/src/components/settings/SettingsOverlayNavigationBoundary.tsx
@@ -1,17 +1,17 @@
import { useContext, useMemo } from 'react';
import type { ReactNode } from 'react';
import {
- parsePath,
+ resolvePath,
+ UNSAFE_DataRouterContext as DataRouterContext,
UNSAFE_NavigationContext as NavigationContext,
useLocation,
} from 'react-router-dom';
-import type { Navigator, To } from 'react-router-dom';
+import type { Navigator, RouterNavigateOptions, To } from 'react-router-dom';
import { settingsOverlayNavigationState } from '@/lib/settingsOverlay';
const destinationPathname = (to: To, fallback: string): string => {
- const pathname = typeof to === 'string' ? parsePath(to).pathname : to.pathname;
- return pathname ?? fallback;
+ return resolvePath(to, fallback).pathname;
};
export const SettingsOverlayNavigationBoundary = ({
@@ -23,6 +23,7 @@ export const SettingsOverlayNavigationBoundary = ({
}) => {
const location = useLocation();
const navigation = useContext(NavigationContext);
+ const dataNavigation = useContext(DataRouterContext);
// Every Settings-bound navigation carries one durable origin. This is the
// ownership point for all links, redirects, and programmatic navigation.
const navigator = useMemo<Navigator>(() => ({
@@ -52,10 +53,43 @@ export const SettingsOverlayNavigationBoundary = ({
() => ({ ...navigation, navigator }),
[navigation, navigator],
);
+ // Data routers bypass NavigationContext and call router.navigate directly.
+ // Keep the same state owner in both router modes so production and tests
+ // cannot disagree about whether Settings has a background location.
+ const scopedDataNavigation = useMemo(() => {
+ if (!dataNavigation) return null;
+ const router = Object.create(dataNavigation.router) as typeof dataNavigation.router;
+ router.navigate = ((
+ to: number | To | null,
+ options?: RouterNavigateOptions,
+ ): Promise<void> => {
+ if (typeof to === 'number' || to === null) {
+ return typeof to === 'number'
+ ? dataNavigation.router.navigate(to)
+ : dataNavigation.router.navigate(to, options);
+ }
+ return dataNavigation.router.navigate(to, {
+ ...options,
+ state: settingsOverlayNavigationState({
+ destinationPathname: destinationPathname(to, location.pathname),
+ desktop,
+ source: location,
+ targetState: options?.state,
+ }),
+ });
+ }) as typeof dataNavigation.router.navigate;
+ return { ...dataNavigation, router };
+ }, [dataNavigation, desktop, location]);
+
+ const content = scopedDataNavigation ? (
+ <DataRouterContext.Provider value={scopedDataNavigation}>
+ {children}
+ </DataRouterContext.Provider>
+ ) : children;
return (
<NavigationContext.Provider value={scopedNavigation}>
- {children}
+ {content}
</NavigationContext.Provider>
);
};
diff --git a/ui/src/components/settings/SettingsOverlayRouteSurface.test.tsx b/ui/src/components/settings/SettingsOverlayRouteSurface.test.tsx
index 9a0929589..f86495d98 100644
--- a/ui/src/components/settings/SettingsOverlayRouteSurface.test.tsx
+++ b/ui/src/components/settings/SettingsOverlayRouteSurface.test.tsx
@@ -10,7 +10,9 @@ import {
Navigate,
Outlet,
Route,
+ RouterProvider,
Routes,
+ createMemoryRouter,
useLocation,
useNavigate,
} from 'react-router-dom';
@@ -162,6 +164,27 @@ afterEach(() => {
});
describe('SettingsOverlayRouteSurface', () => {
+ it('preserves the Chat route with a data router', async () => {
+ const user = userEvent.setup();
+ const router = createMemoryRouter([
+ { path: '*', element: <Harness desktop /> },
+ ], {
+ initialEntries: ['/chat/ses_1'],
+ });
+ render(<RouterProvider router={router} />);
+
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+
+ expect(screen.getByRole('dialog', { name: 'nav.settings' })).toBeTruthy();
+ await user.click(screen.getByRole('button', { name: 'close-settings' }));
+ expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_1');
+
+ await user.click(screen.getByRole('link', { name: 'shell-settings' }));
+ expect(screen.getByRole('dialog', { name: 'nav.settings' })).toBeTruthy();
+ await user.click(screen.getByRole('button', { name: 'shell-settings' }));
+ expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_1');
+ });
+
it('keeps the background route mounted across Settings navigation and close', async () => {
const user = userEvent.setup();
const view = render(
@@ -253,9 +276,9 @@ describe('SettingsOverlayRouteSurface', () => {
await user.click(screen.getByRole('link', { name: 'shell-settings' }));
expect(screen.getByRole('dialog', { name: 'nav.settings' })).toBeTruthy();
- const backdrop = document.querySelector<HTMLElement>('[data-dialog-surface-backdrop="true"]');
- expect(backdrop).not.toBeNull();
- await user.click(backdrop!);
+ expect(document.body.style.pointerEvents).not.toBe('none');
+ expect(document.querySelector('[data-dialog-surface-backdrop="true"]')).toBeNull();
+ await user.click(screen.getByRole('button', { name: 'shell-settings' }));
await waitFor(() => expect(document.querySelector('[data-settings-overlay="true"]')).toBeNull());
expect(screen.getByTestId('chat-location').textContent).toBe('/chat/ses_1');
diff --git a/ui/src/components/settings/SettingsOverlayRouteSurface.tsx b/ui/src/components/settings/SettingsOverlayRouteSurface.tsx
index 7c9f1ac7e..44f791841 100644
--- a/ui/src/components/settings/SettingsOverlayRouteSurface.tsx
+++ b/ui/src/components/settings/SettingsOverlayRouteSurface.tsx
@@ -66,6 +66,7 @@ export const SettingsOverlayRouteSurface = ({
{settingsSurfaceOpen ? (
<Dialog
open
+ modal={false}
onOpenChange={(open) => {
if (!open) closeSettingsOverlay(navigate, origin);
}}
@@ -74,6 +75,15 @@ export const SettingsOverlayRouteSurface = ({
<DialogSurfaceContent
data-settings-overlay="true"
aria-describedby={undefined}
+ onInteractOutside={(event) => {
+ const target = event.target;
+ if (
+ target instanceof Element
+ && target.closest('[data-settings-toggle="true"]')
+ ) {
+ event.preventDefault();
+ }
+ }}
onCloseAutoFocus={(event) => {
event.preventDefault();
window.requestAnimationFrame(() => {