Users reported a bug where paused or finished YouTube videos in Discourse threads automatically restart when scrolling up to load new posts. This occurs because the virtual DOM re-renders iframes during prepending, forcing YouTube players to reload and play. Scrolling down doesn’t trigger this, as appending doesn’t reorder elements. The issue has persisted for years, with attempts by @eviltrout and @Osama failing to resolve it. A user, Aleksey_Bogdanov, proposed a patch to virtual-dom that optimizes prepends, preventing unnecessary re-rendering of existing elements. After testing and refinement—including adding DOM mutation checks and key-based element tracking—the patch was merged into Discourse’s fork of virtual-dom. Although not a perfect general solution, it effectively fixes the YouTube autoplay issue. The team plans to eventually replace the virtual DOM with Ember/Glimmer rendering, which handles prepends correctly. The fix is now live on Meta. david confirmed the patch resolves the issue manually and noted that long-term maintenance of the fork is unnecessary, as Glimmer will replace the post stream within a year.
If a YouTube video in a post is paused or finished playing and you scroll up or down the page enough to load new posts, the aforementioned video will start playing automatically. I’ve successfully recreated this issue on Windows 7 in Chrome version 56.0.2924.87 in this thread: Post your favorite video game glitches - #74 by jacknife - Game Discussion - Let's Play Zone
Load the post in the page above
Play one or all of the videos in the post
Pause them at any point
Scroll up the page until the browser loads in new comments
I have spent a lot of time this afternoon on this issue and I feel like this issue might not be fixable unless someone else has a brilliant idea.
The problem is in the virtual DOM with prepending (scrolling up). In this case, you are adding a bunch of elements (posts) to the beginning of an array. When the virtual DOM does its diff, it notices the element with the youtube <iframe> is not in the same place, so it removes and re-adds it later. This causes the youtube player to refresh the iframe, which causes it to play again.
It seems impossible to move an <iframe> in the DOM without reloading it.
Note that this bug doesn’t happen when scrolling down because appending posts doesn’t change the order. It also doesn’t matter if the user hasn’t started the video already, because lazyYT hasn’t inserted the iframe yet.
OK our debugging shows that for some reason the Youtube embedded player did fix the autoplay thing, so I am fixing the title here.
The bug we have is that we have “protection” in place when you click play that tells the “post cloaker”, hi … don’t cloak me. But this protection is somehow binned when you scroll up.
This means that if you play a song on youtube and scroll up it will just stop playing when we load the next chunk.
Sorry to resurrect this, but I’ve noticed this starts happening now even when scrolling down. Not sure if something changed this bug recently to the worse, or if it’s a different bug altogether. Confirmed with several people in our instance. This makes video sharing threads quite unbearable, when the earlier videos start suddenly playing.
I second this, happens with either scroll up or down and replays all previously played videos randomly (I imagine it has something to do with how Discourse processes previous content when loading new on a Topic, but I honestly don’t know).
I have mixed feelings about this, I don’t think people should have the expectation that a video from 600+ posts above will continue playing as you scroll down endlessly in a megatopic? The video isn’t visible, and hasn’t been visible for a while if you are scrolling down.
e.g. if you want to play audio for a long time while you browse around, on whatever site you’re visiting, open it in a new tab?
It shouldn’t, in my opinion. If the video is paused or finished it shouldn’t replay itself on its own just because you scrolled down. (Which is the described behaviour even though the title is misleading)
As a matter of fact, there is a an alternative for people that want “people to keep playing” as you go around, if they find the tab approach too much.
This still happen on 3.0 stable. Funny thing is one video refresh when scrolling UP, on DOWN its still paused, another random video do the oposite. Stay paused when scroll UP and reftesh play on scroll down.