Skip to content

Fix: removed video from playlist is still associated with the playlist in history#9290

Open
Shadorc wants to merge 8 commits into
FreeTubeApp:developmentfrom
Shadorc:fix/history-playlist
Open

Fix: removed video from playlist is still associated with the playlist in history#9290
Shadorc wants to merge 8 commits into
FreeTubeApp:developmentfrom
Shadorc:fix/history-playlist

Conversation

@Shadorc

@Shadorc Shadorc commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Pull Request Type

  • Bugfix
  • Feature Implementation
  • Documentation
  • Other

Related issue

closes #5870

Description

This one was a lot of digging.
When a video is added to the history db, there are three fields that are set to indicate if it was part of a playlist when watched. These fields are lastViewedPlaylistId, lastViewedPlaylistType and lastViewedPlaylistItemId, they are used to display the playlist view after clicking on the video from the history.
When a video is deleted from a playlist, these fields are not updated.

Testing

Scenario 1: the video is part of only one playlist
Reproduce steps in #5870

Scenario 1bis: the video is part of only one playlist
Reproduce previous steps but change tab within 5 seconds after removing the video from the playlist.

Scenario 2: the video is part of more than one playlist

  1. Add a video to two playlists ('a' and 'b')
  2. Watch the video from playlist 'a'
  3. Delete video from playlist 'b'
  4. Check that when the video is clicked from history, it still show playlist 'a'

Scenario 3: the video was added in a playlist through the quick bookmark button

  1. Add a video to a playlist using the quick bookmark button
  2. Watch the video from the playlist
  3. Delete the video from playlist through the quick bookmark button
  4. Check that when the video is clicked from the history, it does not show any playlist

Additional context

Naming was hard on this one. I take every suggestions that could make this clearer.
Also, I could have used array toBeDeletedPlaylistItemIds to populate with videosId and playlistId but I didn't want to introduce any breaking changes regarding this array so I went with another one.

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) June 15, 2026 00:18
@github-actions github-actions Bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Jun 15, 2026
@Shadorc Shadorc changed the title Fix: removed video from playlist is still associated with the playlist in history Draft: Fix: removed video from playlist is still associated with the playlist in history Jun 15, 2026
@Shadorc Shadorc marked this pull request as draft June 15, 2026 00:35
auto-merge was automatically disabled June 15, 2026 00:35

Pull request was converted to draft

@Shadorc Shadorc changed the title Draft: Fix: removed video from playlist is still associated with the playlist in history Fix: removed video from playlist is still associated with the playlist in history Jun 15, 2026
@github-actions github-actions Bot removed the PR: waiting for review For PRs that are complete, tested, and ready for review label Jun 15, 2026
@Shadorc Shadorc marked this pull request as ready for review June 15, 2026 18:07
@FreeTubeBot FreeTubeBot enabled auto-merge (squash) June 15, 2026 18:07
@github-actions github-actions Bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Jun 15, 2026
@Shadorc

Shadorc commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

I was thinking about maybe reducing store dispatch calls by pre-checking the playlist instead of checking it in unsetLastViewedPlaylist, but the 5-second deletion delay creates a race condition risk in the following scenario:

  • User watches a video from playlist A
  • We remove it from playlist B
  • We pre-check: "Is B the last viewed playlist?" No, so the dispatch call is skipped
  • During those 5 seconds, the user starts watching the same video from playlist B
  • The timer expires and deletes the video from B

Result: The bug still occurs.

This is why I let the database query make the final decision, even though it's a bit less optimized regarding IPC calls

@efb4f5ff-1298-471a-8973-3d47447115dc efb4f5ff-1298-471a-8973-3d47447115dc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Scenario 1 passed but when i tried a slightly modified variant, the video was still associated with the playlist

VirtualBoxVM_UFeyr19WGJ.mp4

@efb4f5ff-1298-471a-8973-3d47447115dc efb4f5ff-1298-471a-8973-3d47447115dc added PR: changes requested and removed PR: waiting for review For PRs that are complete, tested, and ready for review labels Jun 16, 2026
@Shadorc Shadorc marked this pull request as draft June 16, 2026 22:45
auto-merge was automatically disabled June 16, 2026 22:45

Pull request was converted to draft

@Shadorc

Shadorc commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Interesting, thanks for testing!
The bug was occurring when removing a video from a playlist and then going to another tab under 5 seconds.
In this scenario, removeToBeDeletedVideosSometimes is called from onBeforeRouteLeave. This is where it gets a bit weird. removeToBeDeletedVideosSometimes is async, but it is not awaited. This means that the page is changing while the method runs. The first dispatch gets the correct value of playlistId, but the second gets undefined.
The correct fix is probably to await before leaving the route. It may not be supported, or maybe it hides another issue, but when doing so I get a missing param 'id' error message.
I went for the easy fix: storing the playlist ID before it gets changed.

@Shadorc Shadorc marked this pull request as ready for review June 16, 2026 23:37
@FreeTubeBot FreeTubeBot enabled auto-merge (squash) June 16, 2026 23:38
@github-actions github-actions Bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Jun 16, 2026
@efb4f5ff-1298-471a-8973-3d47447115dc efb4f5ff-1298-471a-8973-3d47447115dc removed the PR: waiting for review For PRs that are complete, tested, and ready for review label Jun 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

1,1b and 2 pass

1c doesnt see clip below

VirtualBoxVM_QoOXPrYMCq.mp4

@Shadorc Shadorc marked this pull request as draft June 17, 2026 21:48
auto-merge was automatically disabled June 17, 2026 21:48

Pull request was converted to draft

@Shadorc

Shadorc commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for finding this!

Indeed, removing a video from a playlist can be done from multiple entry points, and the bookmark icon is one of them.

Instead of trying to find every path that leads to a video being removed from a playlist, I think it would be better to directly plug the fix at the lowest level, which is in the playlist store.
I have a concern: this approach would mean that the removeVideo, removeVideos, and removeAllVideos methods from the playlist store would also make a call to the history store. I don't know if that's considered bad practice or if it is fine.

Another solution that comes to my mind would be to have another method that handles both calls to the history and playlist stores, and this would be called instead of directly calling the playlist store.

I can also still search for all paths that lead to videos being removed from playlists, but that doesn't feel future-proof.

What do you think?

@absidue

absidue commented Jun 19, 2026

Copy link
Copy Markdown
Member

Dispatching action calls between stores is fine, the most important thing is to make sure you don't end up creating a loop (store 1 calling into store 2 and store 2 calling into store 1 in response etc).

@Shadorc

Shadorc commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

I have added scenario 1c to the testing section. It has been fixed in a3b5541 (sorry for the yarn.lock, it shouldn't happen again).

To be consistent with the fix, I have also taken into account all the other methods that could impact a playlist or a video in a playlist (a478bda). It is not strictly necessary because if a playlist is deleted from removeAllPlaylists, removePlaylist, or removePlaylists, history won't show the playlist since it already checks if the playlist exists. Concerning removeAllVideos, it is not used.

However, I feel like having an outdated database is worse than adding additional database operations that are not strictly useful. It is handled currently, but it could lead to bugs in the future.

removeAllPlaylists and removePlaylists could be optimized to make one call for all playlists instead of one per playlist, but I first want to check with you what you prefer: reverting the commit or keeping the fix fully implemented (and maybe optimize this a little).

@Shadorc Shadorc marked this pull request as ready for review June 24, 2026 21:43
@FreeTubeBot FreeTubeBot enabled auto-merge (squash) June 24, 2026 21:43
@github-actions github-actions Bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: changes requested PR: waiting for review For PRs that are complete, tested, and ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Removed video from playlist is still associated with the playlist

3 participants