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

songs: keep round-stack playback stable across unrelated re-renders

[._.]/ Adam Eivy887d03390efb
diff --git a/client/src/components/songs/RoundStack.jsx b/client/src/components/songs/RoundStack.jsx
index 882c269652..35a04f886b 100644
--- a/client/src/components/songs/RoundStack.jsx
+++ b/client/src/components/songs/RoundStack.jsx
@@ -33,13 +33,27 @@ export default function RoundStack({ songs = [] }) {
// before awaiting and silence the player if it advanced while we were decoding.
const playGenRef = useRef(0);
+ // Value-stable content signature of every take across the stacked songs.
+ // ReadView hands us a fresh `[song, ...partners]` array on each render, so
+ // keying `takes` off array identity (`[songs]`) would rebuild it — and trip the
+ // takes-changed cleanup that stops playback — on EVERY unrelated parent render
+ // (Save, recording-state updates). This string changes only when the takes
+ // themselves do, keeping `takes` (and the running mix) steady otherwise.
+ const takesKey = songs
+ .flatMap((s) => (s.recordings || []).map((r) => `${s.id}:${r.id}:${r.filename}:${r.muted ? 1 : 0}`))
+ .join('|');
// Every saved take across all stacked songs, keyed by a song-namespaced id so
// two songs' recordings can't collide in the mixer's id map.
- const takes = useMemo(() => songs.flatMap((s) => (s.recordings || []).map((r) => ({
- id: `${s.id}:${r.id}`,
- url: getUploadUrl(r.filename),
- muted: r.muted,
- }))), [songs]);
+ const takes = useMemo(
+ () => songs.flatMap((s) => (s.recordings || []).map((r) => ({
+ id: `${s.id}:${r.id}`,
+ url: getUploadUrl(r.filename),
+ muted: r.muted,
+ }))),
+ // `songs` intentionally excluded — takesKey is its content signature, so an
+ // equivalent-but-new songs array doesn't churn `takes`.
+ [takesKey], // eslint-disable-line react-hooks/exhaustive-deps
+ );
const audibleCount = useMemo(() => takes.filter((t) => !t.muted).length, [takes]);
// Stop and release the mixer on unmount AND whenever the stacked takes change
diff --git a/client/src/components/songs/RoundStack.test.jsx b/client/src/components/songs/RoundStack.test.jsx
index 94b3020efe..3d9b389d91 100644
--- a/client/src/components/songs/RoundStack.test.jsx
+++ b/client/src/components/songs/RoundStack.test.jsx
@@ -111,6 +111,17 @@ describe('RoundStack', () => {
expect(playerCalls.players[0].stop).toHaveBeenCalled();
});
+ it('keeps playing across unrelated re-renders that do not change the recordings', () => {
+ const { rerender } = renderStack(SONGS);
+ fireEvent.click(screen.getByRole('button', { name: /Play all parts/i }));
+ expect(playerCalls.players).toHaveLength(1);
+ // Simulate an unrelated parent render (e.g. Save): a brand-new songs array of
+ // cloned song objects with identical recordings. Playback must NOT tear down.
+ rerender(<MemoryRouter><RoundStack songs={SONGS.map((s) => ({ ...s }))} /></MemoryRouter>);
+ expect(playerCalls.players[0].stop).not.toHaveBeenCalled();
+ expect(playerCalls.players).toHaveLength(1); // no new mixer spun up either
+ });
+
it('does not start the mix if stopped while still decoding', async () => {
playerCalls.deferPlay = true; // play() stays pending until the test resolves it
renderStack(SONGS);