Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (agy): match scopePath on segment boundaries, not a bare prefix
[._.]/ Adam Eivyb344be49a7d4
diff --git a/client/src/hooks/useUnsavedChangesGuard.js b/client/src/hooks/useUnsavedChangesGuard.jsindex 56047c2075..ff4e74300a 100644--- a/client/src/hooks/useUnsavedChangesGuard.js+++ b/client/src/hooks/useUnsavedChangesGuard.js@@ -39,7 +39,13 @@ export default function useUnsavedChangesGuard(isDirty, { beforeUnload = true, sconst shouldBlock = useCallback(({ currentLocation, nextLocation }) => {if (!isDirty) return false;if (currentLocation.pathname === nextLocation.pathname) return false;- return !(scopePath && nextLocation.pathname.startsWith(scopePath));+ // Segment-aware, not a bare `startsWith`: a sibling route that merely+ // shares the prefix (`/…/manuscript-export` against `/…/manuscript`) is a+ // real exit, and letting it through would discard the draft silently.+ const inScope = !!scopePath && (+ nextLocation.pathname === scopePath || nextLocation.pathname.startsWith(`${scopePath}/`)+ );+ return !inScope;}, [isDirty, scopePath]);const blocker = useBlocker(shouldBlock);const blocked = blocker.state === 'blocked';diff --git a/client/src/hooks/useUnsavedChangesGuard.test.jsx b/client/src/hooks/useUnsavedChangesGuard.test.jsxindex a836bc99f8..96211ee83c 100644--- a/client/src/hooks/useUnsavedChangesGuard.test.jsx+++ b/client/src/hooks/useUnsavedChangesGuard.test.jsx@@ -32,6 +32,9 @@ const renderEditor = ({ options, history = [] } = {}) => {{ path: '/away', element: <div>away</div> },{ path: '/edit', element: <Editor options={options} /> },{ path: '/edit/deeper', element: <Editor options={options} /> },+ // A sibling that merely SHARES the '/edit' prefix — leaving to it is a real+ // exit, not an in-scope move.+ { path: '/edit-other', element: <div>other</div> },], { initialEntries: [...history, '/edit'], initialIndex: history.length });render(<RouterProvider router={router} />);return router;@@ -117,6 +120,13 @@ describe('useUnsavedChangesGuard', () => {expect(screen.queryByText('away')).toBeNull();});+ it('blocks a sibling route that merely shares the scopePath prefix', async () => {+ const router = renderEditor({ options: { scopePath: '/edit' } });+ await navigate(router, '/edit-other');+ expect(await screen.findByText('keep')).toBeTruthy();+ expect(screen.queryByText('other')).toBeNull();+ });+it('arms beforeunload while dirty and disarms once clean', async () => {const add = vi.spyOn(window, 'addEventListener');const remove = vi.spyOn(window, 'removeEventListener');