YouTube embeds get randomly swapped around when there are many of them?

We’re encountering a very weird bug, and what makes it weirder is that it only happens for some readers.

On this post which has many YouTube embeds (kg-embed-card), some readers see the YouTube videos under the wrong headings - a different heading to what they’re under in the backend/editor. It’s as if something is randomly swapping just the YouTube embeds around, but nothing else.

You can see their complaints in the comments, for what it’s worth.

None of our theme scripts even touch kg-embed-card, nevermind swapping them around randomly, and we cannot reproduce it ourselves.

Oh and it’s definitely not being caused by our ads provider, because a paid member is also reporting it, and we use #unless @member.paid in our theme to never even load the ad provider scripts for paid members.

This is a very strange bug for which we can find no rational explanation. It has to either be something to do with how Ghost is serving the HTML, or something on YouTube’s side with how they handle multiple embeds on the same page.

Anyone have any clue how we’d even go about debugging this, nevermind what’s actually causing it?


Setup information

Ghost Version*
6.5.3-0-g1bf03996+moya*

How did you install Ghost?
Ghost(Pro)

Browser & OS version
Readers have reported this on iOS Firefox, mobile Chrome, and mobile Brave.

1 Like

Is it often enough that you can reproduce it? I’d want to look at the page source when it happens. Are the embeds in the right place in the source? (Ctrl-U)

If they’re right in source and wrong in the fully loaded page, that narrows it down to JavaScript. Most themes run some sort of reframing script to get the video embeds the right size, so I’d probably start by looking there. Most of your reports are mobile, which might suggest a race condition that appears when loading times are slow?

1 Like

None of us (staff) have been able to reproduce it, only (some of) our readers are experiencing it.

We do not use a reframing script for the video embeds. I know what you’re referring to, such as fitvids, but we’re not using any. I’ve combed our entire theme and confirmed that there is nothing that even touches the iFrame or embed card, nevermind moves it.

(I also had Codex look through the full theme and confirm the same - there is nothing there that could cause this)

I’ll try to simulate a very slow loading time and see if I can reproduce it that way.

1 Like