Skip to content

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

fix: run a queued SongBook exit after the save that settles it, and pass modified clicks through (#3902)

[._.]/ Adam Eivy9ca899d69597
diff --git a/client/src/pages/SongBookViewer.jsx b/client/src/pages/SongBookViewer.jsx
index 36fa84d40f..dae65f834f 100644
--- a/client/src/pages/SongBookViewer.jsx
+++ b/client/src/pages/SongBookViewer.jsx
@@ -348,17 +348,27 @@ export default function SongBookViewer() {
[song, draft],
);
const [pendingExit, setPendingExit] = useState(null);
- // A save (or a discard) settles the draft — any armed confirm is now moot.
- useEffect(() => { if (!isDirty) setPendingExit(null); }, [isDirty]);
+ // Once the draft settles — the user hit Save with an exit armed, or typed the
+ // value back to what's stored — the exit they asked for RUNS rather than being
+ // dropped. Dropping it would swallow the click: the confirm hides with the
+ // draft clean and nothing ever navigates. (Discard clears `pendingExit`
+ // itself before resetting the draft, so it can't double-fire here.)
+ useEffect(() => {
+ if (isDirty || !pendingExit) return;
+ setPendingExit(null);
+ pendingExit();
+ }, [isDirty, pendingExit]);
// Store the exit as a value, not as a state updater (setState(fn) would CALL it).
const requestExit = useCallback((run) => {
if (isDirty) setPendingExit(() => run);
else run();
}, [isDirty]);
// Route-link clicks can't be deferred by returning false — swallow the default
- // navigation and re-run it from the confirm instead.
+ // navigation and re-run it from the confirm instead. A modified click
+ // (⌘/Ctrl/Shift/Alt, or a middle button) opens a second tab and LEAVES the
+ // editor standing, so there's nothing to guard: let the browser have it.
const onLeaveLink = useCallback((e) => {
- if (!isDirty) return;
+ if (!isDirty || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;
e.preventDefault();
setPendingExit(() => () => navigate('/songbook'));
}, [isDirty, navigate]);
diff --git a/client/src/pages/SongBookViewer.test.jsx b/client/src/pages/SongBookViewer.test.jsx
index 104aee5e1d..f5cba6f50a 100644
--- a/client/src/pages/SongBookViewer.test.jsx
+++ b/client/src/pages/SongBookViewer.test.jsx
@@ -652,8 +652,21 @@ K: o - - - - - o -`;
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => expect(screen.queryByRole('button', { name: 'Discard' })).toBeNull());
expect(screen.getByRole('button', { name: 'Saving…' })).toBeTruthy();
+ // The save settles the draft, so the exit the user asked for runs instead
+ // of being swallowed with the confirm row.
resolveSave();
- await waitFor(() => expect(api.updateSong).toHaveBeenCalled());
+ await waitFor(() => expect(screen.queryByLabelText('Content')).toBeNull());
+ expect(api.updateSong).toHaveBeenCalled();
+ });
+
+ it('lets a modified click open All songs in a new tab without prompting', async () => {
+ renderPage('/songbook/abc?mode=edit');
+ await editSheet();
+ // ⌘/Ctrl-click opens a second tab and leaves this editor standing — there
+ // is no unsaved work at risk, so the guard must not swallow it.
+ fireEvent.click(screen.getByRole('link', { name: /All songs/ }), { metaKey: true });
+ expect(screen.queryByText(/Discard your unsaved changes/)).toBeNull();
+ expect(screen.getByLabelText('Content').value).toBe('Edited sheet text');
});
it('drops the armed confirm once a save settles the draft', async () => {