diff --git a/src/components/AddDownloadsModal.tsx b/src/components/AddDownloadsModal.tsx index 96aca81..3e80479 100644 --- a/src/components/AddDownloadsModal.tsx +++ b/src/components/AddDownloadsModal.tsx @@ -373,6 +373,13 @@ export const AddDownloadsModal = () => { break; } requestSet.add(requestKey); + if (row.isPlaylist) { + // Invalidate stale playlist requests before any asynchronous settings, + // keychain, or network work can yield. Otherwise an old request can + // become the latest request again after the URL or browser context + // has already changed. + latestPlaylistRequestRef.current.set(row.sourceUrl, requestKey); + } void (async () => { try { @@ -411,7 +418,6 @@ export const AddDownloadsModal = () => { if (row.isPlaylist) { if (playlistExpansions[row.sourceUrl]) return; - latestPlaylistRequestRef.current.set(row.sourceUrl, requestKey); const playlistData = await fetchMediaPlaylistMetadataDeduped({ ...mediaMetadataArgs, url: contextUrl @@ -1047,11 +1053,11 @@ export const AddDownloadsModal = () => {