Fix Race Condition

This commit is contained in:
2026-02-19 23:53:48 +11:00
parent 68fc92b2db
commit df80ef748e
+6
View File
@@ -1298,6 +1298,7 @@ interface WordLyricsResponse {
} }
// syllable state // syllable state
let trackChangeToken = 0;
let lyricsData: WordLine[] | null = null; let lyricsData: WordLine[] | null = null;
let tickLoopId: number | null = null; let tickLoopId: number | null = null;
let isActive = false; let isActive = false;
@@ -1696,6 +1697,7 @@ const clearTickLoop = (): void => {
// teardown (cleanup) // teardown (cleanup)
const teardown = (): void => { const teardown = (): void => {
trackChangeToken++;
clearTickLoop(); clearTickLoop();
unwatchRerender(); unwatchRerender();
unhookUserScroll(); unhookUserScroll();
@@ -1990,7 +1992,10 @@ const onTrackChange = async (): Promise<void> => {
if (settings.lyricsStyle === 0) return; if (settings.lyricsStyle === 0) return;
const token = ++trackChangeToken;
const trackInfo = await getTrackInfo(); const trackInfo = await getTrackInfo();
if (token !== trackChangeToken) return;
if (!trackInfo) { if (!trackInfo) {
trace.log("Word lyrics: could not get track info from playback state"); trace.log("Word lyrics: could not get track info from playback state");
return; return;
@@ -2004,6 +2009,7 @@ const onTrackChange = async (): Promise<void> => {
trackInfo.title, trackInfo.title,
trackInfo.artist, trackInfo.artist,
); );
if (token !== trackChangeToken) return;
if (!response) { if (!response) {
trace.log("Word lyrics: no word-level lyrics for this track"); trace.log("Word lyrics: no word-level lyrics for this track");
return; return;