fix: normalize youtube url in Embed#1524
Draft
eaglethrost wants to merge 1 commit into
Draft
Conversation
kevinports
reviewed
Jun 30, 2026
kevinports
left a comment
Contributor
There was a problem hiding this comment.
Def on board for this improvement! Just had a few pieces of code feedback.
|
|
||
| if (iframe || renderTypeAsIframe) { | ||
| return <iframe {...spreadAttrs} src={url} style={iframeStyle} title={title} />; | ||
| const src = typeOfEmbed === 'youtube' ? normalizeYouTubeUrl(url) : url; |
Contributor
There was a problem hiding this comment.
Should we move the normalization upstream to processor/transform/embeds.ts to make the UI component agnostic to the URL format?
This would also make it easier to handle edge conditions like if a consumer passes iframe={true} + a YouTube watch URL but omits typeOfEmbed or whatever.
| @@ -0,0 +1,38 @@ | |||
| // YouTube watch/share URLs (youtube.com/watch?v=ID, youtu.be/ID) set X-Frame-Options | |||
| // and refuse to be framed. The player only allows embedding via youtube.com/embed/ID. | |||
| const YOUTUBE_HOSTS = new Set(['youtube.com', 'www.youtube.com', 'm.youtube.com', 'youtu.be', 'www.youtu.be']); | |||
Contributor
There was a problem hiding this comment.
I think the m.youtu.be mobile share link host is also plausible and could be included here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 What does this PR do?
YouTube watch/share URLs set
X-Frame-Optionsand refuse to be framed, sotypeOfEmbed="youtube"embeds rendered blank. We can fix this in the background so they'll still be viewable by normalising them to the embeddableyoutube.com/embed/<id>form (carrying any timestamp over tostart).All three now render an
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ">(the last with?start=3723). Already-embeddable and non-YouTube URLs pass through untouched.🧪 QA tips
📸 Screenshot or Loom