Skip to content

fix: reverse playlist persists across video navigation (fixes #3759, #3818, #3883)#3946

Open
jiangyj545 wants to merge 1 commit into
code-charity:masterfrom
jiangyj545:fix/reverse-playlist-persist-3759
Open

fix: reverse playlist persists across video navigation (fixes #3759, #3818, #3883)#3946
jiangyj545 wants to merge 1 commit into
code-charity:masterfrom
jiangyj545:fix/reverse-playlist-persist-3759

Conversation

@jiangyj545

@jiangyj545 jiangyj545 commented Jun 9, 2026

Copy link
Copy Markdown

(running playlistReverseUpdate() twice with 1.5s delay)

Fix for #3759, #3818, #3883 — Reverse playlist reverts on video navigation

### Problem When "Reverse Playlist" is active and the user navigates to the next video in the playlist, YouTube's SPA navigation triggers `yt-page-data-updated`. The extension calls `playlistReverseUpdate()`, but at this point `ytd_watch.data` may not be populated yet, so the function returns early without applying the reverse. The playlist then renders in its original order.

Solution

Add a delayed retry (1.5s) in playlistReverse(). After the initial playlistReverseUpdate() call, a setTimeout fires once more to catch the case where the first attempt returned early because playlist data wasn't ready.

This is minimal and safe:

  • Only retries when playlistReversed is still true
  • Does not add an interval or loop — just one additional attempt
  • The existing isCurrentlyReversed === shouldBeReversed guard in playlistReverseUpdate() prevents double-reversing if the first call succeeded

Changes

File Change
playlist.js Added 1.5s delayed retry of playlistReverseUpdate() in playlistReverse()

Testing

  • 66/69 unit tests pass (3 pre-existing failures unrelated to this change)
  • JS-only change, no CSS or HTML modifications

@ImprovedTube2

Copy link
Copy Markdown
Collaborator

hi! @suryaprakash0010 #3766

@ImprovedTube2 ImprovedTube2 added untested please test. (also applies to proactively merged pull requests.) Generated labels Jun 10, 2026
@Hyperspeed1313

Copy link
Copy Markdown

Try the latest release first? #3643 should've already fixed this

@wahajahmed010 wahajahmed010 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Reverse playlist SPA fix

Potential issues:

  1. Stale setTimeout pileupsetTimeout has no cleanup. If the user navigates between videos quickly, multiple 1.5s delays stack up. The ImprovedTube.playlistReversed === true guard helps but stale callbacks from earlier navigations could run when the user is on a different video. Consider storing & clearing the timeout ID.

  2. #3643 overlap — Hyperspeed1313 noted #3643 may already fix this. PR references 3 issues — worth clarifying if they persist after #3643.

  3. Magic number — 1500ms works empirically but could be a named constant with rationale.

What looks good:

  • Minimal single-file change
  • Guard prevents double-reverse
  • Real SPA race condition addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Generated untested please test. (also applies to proactively merged pull requests.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants