Fixed missing videochange dataupdated event when using shuffle #3659
No reviewers
Labels
No labels
awaiting-reply
breaking changes
bug
cannot-reproduce
dependencies
documentation
duplicate
electron-issue
enhancement
fix-available
good first issue
help wanted
invalid
javascript
need more information
need rebase
official-youtube-music-issue
plugin request
question
release
security
stale
Status: blocked
typo
wontfix
ytmd-issue
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: YTMD/youtube-music#3659
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/missing-dataupdated-event"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fix issue where videochange-dataupdated event doesn't fire after shuffle
After triggering shuffle via the API, the videochange: dataupdated event sometimes fails to fire. To ensure the song info is still updated, a fallback using a timeout has been implemented.
Pull Request Overview
This PR fixes an issue where the
videochange-dataupdated
event doesn't fire after shuffle operations, which could leave song info in an outdated state. The solution implements a fallback mechanism using timeouts to ensure song information is updated even when the expected event doesn't fire.dataupdated
events@ -222,7 +237,18 @@ export default (api: YoutubePlayer) => {
video?.addEventListener(status, playPausedHandlers[status]);
}
clearVideoTimeout(videoData.videoId);
The timeout value of 1500ms is a magic number. Consider extracting this to a named constant with a descriptive name like
DATAUPDATED_FALLBACK_TIMEOUT_MS
to improve code maintainability and make it easier to adjust if needed.The event listener is added but never removed. Consider storing a reference to enable cleanup, or use the
{ once: true }
option if this is intended to be a one-time listener. This prevents potential memory leaks if this code runs multiple times.If
dataupdated
is not fired,videoData
may be incompletely loaded. In this case, the behavior of some plugins may be broken.Yet this is the best option, because without the fallback to first event the data isn't updated at all. Even if I press next song
Seems like in the case when
dataupdated
isn't fired,dataloaded
has all data just like thedataupdated
, but someone else need to test and confirm it@ -224,2 +239,4 @@
clearVideoTimeout(videoData.videoId);
waitingEvent.add(videoData.videoId);
This seems redundant, doesn't the window automatically destroy all related resources when it unloads?
@ -224,2 +239,4 @@
clearVideoTimeout(videoData.videoId);
waitingEvent.add(videoData.videoId);
Or did I misunderstand this, and the event gets fired even when the window does not unload?
@ -224,2 +239,4 @@
clearVideoTimeout(videoData.videoId);
waitingEvent.add(videoData.videoId);
Hmm, yeah, this one is redundant