Fix/player desync on lyrics update#237
Merged
theovilardo merged 2 commits intomasterfrom Oct 11, 2025
Merged
Conversation
When lyrics were updated for the current song (either via online search, accepting a search result, or importing a file), the `PlayerViewModel` would only update the `Song` object instance within the `stablePlayerState`. The corresponding `Song` object within the `playerUiState.currentPlaybackQueue` remained unchanged. This created a state inconsistency. When the UI recomposed, `AlbumCarouselSection` would use the new `currentSong` object to find its index within the old `currentPlaybackQueue`. Because the object references did not match, `indexOf` would return -1 (coerced to 0), causing the carousel to reset to the first song. This also caused the progress bar and other UI elements to desynchronize. This fix addresses the issue by ensuring that whenever a song's lyrics are updated, the change is propagated to both `stablePlayerState.currentSong` and the corresponding object in `playerUiState.currentPlaybackQueue`. This is done by finding the song's index, creating an updated `Song` object, and replacing the old instance in the queue, thus maintaining state consistency.
This commit refactors the `PlayerViewModel` to introduce a centralized private function, `updateSongInStates`. This function is now the single source of truth for updating a song's metadata, ensuring that both the `stablePlayerState` and the `playerUiState.currentPlaybackQueue` are updated atomically and consistently. Previously, when lyrics were updated (via online search, accepting a result, or importing a file), the different functions updated the state inconsistently. This created a race condition where the `currentSong` object instance in `stablePlayerState` would be different from the instance in the `currentPlaybackQueue`. When the UI recomposed, it would fail to find the new song object in the old queue, causing it to default to the first item and desynchronizing the player UI (album art, progress bar, etc.). By refactoring `fetchLyricsForCurrentSong`, `acceptLyricsSearchResultForCurrentSong`, and `importLyricsFromFile` to use the new unified update function, this commit resolves the bug and improves the robustness of the state management logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.