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): Enter-key form-submit hijack, unguarded selects, double-click re-entrancy

[._.]/ Adam Eivy0b188bee9da8
diff --git a/client/src/hooks/useYoutubeTrackImport.js b/client/src/hooks/useYoutubeTrackImport.js
index d99b987e22..008dd26aca 100644
--- a/client/src/hooks/useYoutubeTrackImport.js
+++ b/client/src/hooks/useYoutubeTrackImport.js
@@ -1,4 +1,4 @@
-import { useEffect, useState } from 'react';
+import { useEffect, useRef, useState } from 'react';
import toast from '../components/ui/Toast';
import { importTrackFromYoutube, cancelTrackImport, trackImportEventsUrl } from '../services/apiTracks.js';
import { useSseProgress, isTerminalSseFrame } from './useSseProgress.js';
@@ -20,6 +20,11 @@ export default function useYoutubeTrackImport({ onComplete } = {}) {
const [job, setJob] = useState(null); // { jobId, context }
const sse = useSseProgress(job ? trackImportEventsUrl(job.jobId) : null);
const percent = Math.round(sse.latest?.percent ?? 0);
+ // Synchronous re-entrancy guard for the gap between clicking Import and the
+ // kickoff request resolving — `job` (state) doesn't flip true until then,
+ // so a fast double-click would otherwise fire two requests and the second
+ // response's setJob would silently orphan the first job.
+ const startingRef = useRef(false);
useEffect(() => {
const frame = sse.latest;
@@ -48,10 +53,12 @@ export default function useYoutubeTrackImport({ onComplete } = {}) {
const start = (url, context) => {
const trimmed = url.trim();
- if (!trimmed) return;
+ if (!trimmed || job || startingRef.current) return;
+ startingRef.current = true;
importTrackFromYoutube(trimmed, { silent: true })
.then(({ jobId }) => setJob({ jobId, context }))
- .catch((err) => toast.error(err?.message || 'Failed to start YouTube import'));
+ .catch((err) => toast.error(err?.message || 'Failed to start YouTube import'))
+ .finally(() => { startingRef.current = false; });
};
const cancel = () => {
diff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsx
index 4c9b087fa0..5448eba59c 100644
--- a/client/src/pages/MusicVideo.jsx
+++ b/client/src/pages/MusicVideo.jsx
@@ -52,6 +52,12 @@ function YoutubeImportControls({ id, url, onUrlChange, job, onStart, compact = f
<>
<input
id={id} type="url" value={url} onChange={onUrlChange} disabled={job.active}
+ // The create form's usage sits inside a <form onSubmit={handleCreate}>
+ // — without this, Enter (the natural gesture after pasting a URL)
+ // submits the form (creating a track-less project) instead of
+ // starting the import. Harmless on the detail view's usage, which
+ // isn't inside a <form>.
+ onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); if (url.trim()) onStart(); } }}
placeholder="Import audio from a YouTube URL…" aria-label="Import audio from a YouTube URL"
className={`${compact ? 'flex-1 min-w-[160px]' : 'flex-1 min-w-0'} bg-port-bg border border-port-border rounded px-2 ${py} text-sm disabled:opacity-50`}
/>
@@ -478,7 +484,8 @@ export default function MusicVideo() {
</select>
<label htmlFor="mv-track" className="block text-xs text-port-text-muted">Track (optional)</label>
<select id="mv-track" value={form.trackId} onChange={(e) => setForm((f) => ({ ...f, trackId: e.target.value }))}
- className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm">
+ disabled={ytImportCreate.active}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm disabled:opacity-50">
<option value="">— no track —</option>
{tracks.map((t) => <option key={t.id} value={t.id}>{t.title || t.id}</option>)}
</select>
@@ -568,7 +575,8 @@ export default function MusicVideo() {
<span className="text-port-text-muted flex items-center gap-1"><Music size={12} /> {trackName(selected.trackId)}</span>
<select value={selected.trackId || ''} aria-label="Change track"
onChange={(e) => e.target.value && handleChangeTrack(e.target.value)}
- className="bg-port-bg border border-port-border rounded px-1.5 py-1">
+ disabled={ytImportEdit.active}
+ className="bg-port-bg border border-port-border rounded px-1.5 py-1 disabled:opacity-50">
<option value="">Change track…</option>
{tracks.map((t) => <option key={t.id} value={t.id}>{t.title || t.id}</option>)}
</select>
diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsx
index 8b2d81ddc0..012f0f7055 100644
--- a/client/src/pages/MusicVideo.test.jsx
+++ b/client/src/pages/MusicVideo.test.jsx
@@ -71,7 +71,8 @@ vi.mock('../components/PageHeader', () => ({ default: ({ title }) => <div>{title
import MusicVideo from './MusicVideo.jsx';
import {
- listMusicVideoProjects, renderMusicVideoProject, planMusicVideoProject, updateMusicVideoProject, deleteMusicVideoProject,
+ listMusicVideoProjects, createMusicVideoProject, renderMusicVideoProject, planMusicVideoProject, updateMusicVideoProject,
+ deleteMusicVideoProject,
} from '../services/apiMusicVideo.js';
import { importTrackFromYoutube, trackImportEventsUrl } from '../services/apiTracks.js';
@@ -246,4 +247,28 @@ describe('MusicVideo YouTube audio import (#1945)', () => {
expect(toast.error).toHaveBeenCalledWith(expect.stringMatching(/before deleting this project/i));
expect(deleteMusicVideoProject).not.toHaveBeenCalled();
});
+
+ it('pressing Enter in the create-form URL input starts the import instead of submitting the form', async () => {
+ listMusicVideoProjects.mockResolvedValue([]);
+ render(<MusicVideo />);
+ const createInput = await screen.findByPlaceholderText(/Import audio from a YouTube URL/i);
+ fireEvent.change(createInput, { target: { value: 'https://youtu.be/enterkey' } });
+ fireEvent.keyDown(createInput, { key: 'Enter' });
+ await waitFor(() => expect(importTrackFromYoutube).toHaveBeenCalledWith('https://youtu.be/enterkey', { silent: true }));
+ expect(createMusicVideoProject).not.toHaveBeenCalled();
+ });
+
+ it('ignores a second Import click while the first kickoff request is still in flight', async () => {
+ listMusicVideoProjects.mockResolvedValue([]);
+ let resolveKickoff;
+ importTrackFromYoutube.mockImplementation(() => new Promise((resolve) => { resolveKickoff = resolve; }));
+ render(<MusicVideo />);
+ const createInput = await screen.findByPlaceholderText(/Import audio from a YouTube URL/i);
+ fireEvent.change(createInput, { target: { value: 'https://youtu.be/doubleclick' } });
+ const importBtn = within(createInput.closest('div')).getByRole('button', { name: /Import/i });
+ fireEvent.click(importBtn);
+ fireEvent.click(importBtn); // fires before the first request resolves
+ resolveKickoff({ jobId: 'yt-job-1' });
+ await waitFor(() => expect(importTrackFromYoutube).toHaveBeenCalledTimes(1));
+ });
});