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.

2.5 KB
Raw Blame

Issue 803: Router-wide unsaved changes guard

Background

The full-page Editor introduced in #800 keeps unsaved buffers inside the routed page. Its hard-unload and window-close guards do not protect desktop links, imperative SPA navigation, or browser Back. The interim NavGuardContext covers only selected mobile controls because BrowserRouter cannot use React Router's supported useBlocker API.

Goal

Give every route-mounted dirty surface one reusable registration contract while keeping exactly one router blocker. Preserve hard-unload protection and keep windowed-app close behavior independent.

Design

  • Replace the root BrowserRouter with createBrowserRouter and RouterProvider, retaining the current pathless auth/AppShell layout and all child routes.
  • Mount UnsavedChangesProvider as the data router's root layout. It owns the only useBlocker and a stable-identity message registry.
  • Aggregate both full-page Editor variants' dirty state in AppsEditorPage, then register once and retain the existing beforeunload listener.
  • Remove manual AppShell confirmation wrappers. Links, imperative navigation, and POP transitions all pass through the central blocker; window close guards remain unchanged.
  • Keep unread clearing owned by the mounted ChatPage, not navigation click handlers, so a blocked transition cannot mutate session state before the user confirms it.
  • Let data-mutating actions that need a generated route pre-authorize exactly one synchronous navigation through the same Provider. Cancel happens before mutation and successful actions do not trigger a second prompt or leave a reusable bypass behind.

Verification

  • Registry unit tests
  • Changed-file lint and UI typecheck/build
  • Desktop sidebar cancel/confirm with buffer preservation
  • Browser Back cancel, retry, and confirm
  • Mobile bottom navigation and Back
  • Imperative navigation, clean navigation, and hard-unload listener
  • Canceled session navigation sends no mark-read request; confirmed navigation marks once
  • Canceled new-session action creates nothing; confirmed creation navigates with one prompt
  • Setup/auth/remote redirect, lazy Apps routes, and legacy redirects
  • Local Incus worktree service and mobile blocker smoke

The repository-wide ESLint command still reports the existing baseline (333 errors and 42 warnings, including unchanged code in App.tsx and AppShell.tsx). The new modules pass ESLint, and the changed existing files pass after suppressing only their baseline rule categories.