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

address review (claude): discard unsaved concept/style draft on project switch

[._.]/ Adam Eivyb5dbbc706361
diff --git a/client/src/hooks/useFieldDraft.js b/client/src/hooks/useFieldDraft.js
index 995d462fc5..19855a92ba 100644
--- a/client/src/hooks/useFieldDraft.js
+++ b/client/src/hooks/useFieldDraft.js
@@ -24,5 +24,11 @@ export default function useFieldDraft(persisted, onCommit) {
setDraft(undefined);
};
- return { value, onChange, onBlur };
+ // Discards a pending, uncommitted edit without firing onCommit — for a caller
+ // whose `persisted` identity can change out from under a still-focused input
+ // (e.g. the user navigates to a different record before blurring), so the
+ // stale draft can't be blurred onto the new record on the next unrelated blur.
+ const reset = () => setDraft(undefined);
+
+ return { value, onChange, onBlur, reset };
}
diff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsx
index aa52558f28..00d0835283 100644
--- a/client/src/pages/MusicVideo.jsx
+++ b/client/src/pages/MusicVideo.jsx
@@ -478,6 +478,13 @@ export default function MusicVideo() {
// and a focus-without-edit blur doesn't re-PATCH an unchanged value.
const conceptDraft = useFieldDraft(selected?.concept?.prompt, (v) => commitConcept({ prompt: v }));
const styleDraft = useFieldDraft(selected?.concept?.style, (v) => commitConcept({ style: v }));
+ // The route (not a remount) drives which project is "selected" here, so a
+ // still-focused, unblurred draft survives a project switch (deep link,
+ // browser Back, future ⌘K/voice jump) with the OLD project's typed text.
+ // Without this, the next incidental blur would commit that leftover draft
+ // onto the NEW project via commitConcept's captured `selected`. Discard
+ // (never auto-commit) any pending edit the instant the selection changes.
+ useEffect(() => { conceptDraft.reset(); styleDraft.reset(); }, [selectedId]);
// BeatTimeline drag commit — same optimistic-local + silent-PATCH pattern as
// the other scene field editors (#1854).
const commitSceneTiming = (sceneId, patch) => {
diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsx
index 67e79bdcfa..9bf2dd5baa 100644
--- a/client/src/pages/MusicVideo.test.jsx
+++ b/client/src/pages/MusicVideo.test.jsx
@@ -285,6 +285,31 @@ describe('MusicVideo concept & style editor (#3168)', () => {
expect(updateMusicVideoProject).not.toHaveBeenCalled();
});
+ it('discards an unsaved draft on project switch instead of leaking it onto the next project', async () => {
+ // The page reuses one component instance across projects (route param
+ // change, no remount) — an edit left unblurred when the selection changes
+ // (deep link, browser Back, ⌘K) must not survive to be committed against
+ // whichever project is now selected.
+ const projectB = { ...PROJECT_NO_CLIP, id: 'mv-3', name: 'Other Project', concept: { prompt: 'B original' } };
+ listMusicVideoProjects.mockResolvedValue([PROJECT_NO_CLIP, projectB]);
+ renderMV();
+ fireEvent.click(await screen.findByRole('button', { name: new RegExp(PROJECT_NO_CLIP.name) }));
+
+ const conceptField = await screen.findByLabelText('Concept');
+ fireEvent.change(conceptField, { target: { value: 'A unsaved draft' } });
+ // No blur — switch projects while the edit is still pending.
+ fireEvent.click(screen.getByRole('button', { name: new RegExp(projectB.name) }));
+
+ await waitFor(() => expect(screen.getByLabelText('Concept')).toHaveValue('B original'));
+ fireEvent.blur(screen.getByLabelText('Concept'));
+ await settle();
+ expect(updateMusicVideoProject).not.toHaveBeenCalledWith(
+ 'mv-3',
+ { concept: { prompt: 'A unsaved draft' } },
+ { silent: true },
+ );
+ });
+
it('starts empty and enables AI Plan to use them once set', async () => {
await openProject(PROJECT_ANALYZED);
const conceptField = await screen.findByLabelText('Concept');