From 16f4f0c9edbacdc645c563bf7a7c38ffd9adfe20 Mon Sep 17 00:00:00 2001 From: nemesbak Date: Thu, 28 May 2026 13:39:04 +0200 Subject: [PATCH 1/2] fix(frontend): clean up profiles state when playlists are deleted removePlaylists() filtered the playlists array but never removed the corresponding entries from the profiles map (the @TODO left since the store was introduced). Any component reading profiles[id] after deletion would get undefined and crash with 'undefined is not an object (evaluating P[R].name)'. Fix: build a copy of profiles with the deleted IDs removed and include it in the state update alongside the filtered playlists array. Fixes #1269 Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/store/playlists.jsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/src/store/playlists.jsx b/frontend/src/store/playlists.jsx index 30d01906..8050a7c3 100644 --- a/frontend/src/store/playlists.jsx +++ b/frontend/src/store/playlists.jsx @@ -86,12 +86,16 @@ const usePlaylistsStore = create((set) => ({ })), removePlaylists: (playlistIds) => - set((state) => ({ - playlists: state.playlists.filter( - (playlist) => !playlistIds.includes(playlist.id) - ), - // @TODO: remove playlist profiles here - })), + set((state) => { + const updatedProfiles = { ...state.profiles }; + playlistIds.forEach((id) => delete updatedProfiles[id]); + return { + playlists: state.playlists.filter( + (playlist) => !playlistIds.includes(playlist.id) + ), + profiles: updatedProfiles, + }; + }), setRefreshProgress: (accountIdOrData, data) => set((state) => { From df6f98a80693b7efbad936811dacf1dd9a7d6d75 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Sat, 30 May 2026 12:43:41 -0500 Subject: [PATCH 2/2] tests: Add tests for playlist deletion. --- .../src/store/__tests__/playlists.test.jsx | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/frontend/src/store/__tests__/playlists.test.jsx b/frontend/src/store/__tests__/playlists.test.jsx index da653259..247ec2a6 100644 --- a/frontend/src/store/__tests__/playlists.test.jsx +++ b/frontend/src/store/__tests__/playlists.test.jsx @@ -194,15 +194,25 @@ describe('usePlaylistsStore', () => { }); }); - it('should remove playlists', () => { + it('should remove playlists and their profiles', () => { const { result } = renderHook(() => usePlaylistsStore()); act(() => { - result.current.playlists = [ - { id: 'playlist1', name: 'Playlist 1' }, - { id: 'playlist2', name: 'Playlist 2' }, - { id: 'playlist3', name: 'Playlist 3' }, - ]; + result.current.addPlaylist({ + id: 'playlist1', + name: 'Playlist 1', + profiles: ['profile1'], + }); + result.current.addPlaylist({ + id: 'playlist2', + name: 'Playlist 2', + profiles: ['profile2'], + }); + result.current.addPlaylist({ + id: 'playlist3', + name: 'Playlist 3', + profiles: ['profile3'], + }); }); act(() => { @@ -210,8 +220,11 @@ describe('usePlaylistsStore', () => { }); expect(result.current.playlists).toEqual([ - { id: 'playlist2', name: 'Playlist 2' }, + { id: 'playlist2', name: 'Playlist 2', profiles: ['profile2'] }, ]); + expect(result.current.profiles).toEqual({ playlist2: ['profile2'] }); + expect(result.current.profiles.playlist1).toBeUndefined(); + expect(result.current.profiles.playlist3).toBeUndefined(); }); it('should set refresh progress with two parameters', () => {