Spotify embed: playlist/album embeds show empty space
Description
Embedding a single song with the Spotify embed works just fine, but if you try to add an album/playlist - basically any embed with more than one song - it shows extra empty space below the actual embed area.
Seems like it's part of the iframe, and I have to guess it's the list items below the displayed song which does this.
FWIW this happens both with core WordPress and also with Gutenberg so I am not sure where's the best place to put it.
Step-by-step reproduction instructions
- Create a new page/post/item of choice
- Embed a Spotify playlist/album/other multiple-song embed
- Gap appears both in editor and in live view.
Screenshots, screen recording, code snippet
This is zoomed out at 67% to get all three in there, because I remembered that columns are a thing afterwards:
Close-up with the code, it's definitely the additional songs there, along with the buttons that are hidden in the kebab menu:
Environment info
WordPress 6.2.2 Gutenberg 15.9.1 (admittedly optional, this happens in core but I noticed a couple of other related issues: Classic block Spotify embeds styled differently from Spotify block and Spotify embed block should allow for setting height ) Theme tested: TT3; I did test a non-Site Editor theme too though and it happens there as well.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Thanks for reporting @sophiegyo. This issue was reviewed in today's Editor Bug Scrub and we were able to confirm the issue. I have updated the labels accordingly.
Any solution ?
Just raising that this is still happening as of GB 17.8. Turning off "Resize for smaller devices" mostly fixes the issue on desktop with the drawback of having a larger embed.
@ndiego I've spotted this bug as well it sounds like to be due to the code below: https://github.com/WordPress/gutenberg/blob/4b8c74ff010c65b2ddf03de2a2546f759595e0fd/packages/block-library/src/embed/util.js#L221 Here we expect width to be a number but "100%" is received. Maybe if we could use the editor "contentSize" instead of "100%" that would work?
Root Cause
As per @staurand suggestion, The getClassNames() function in util.js calculates aspect ratios using iframe.width / iframe.height. Spotify iframes use width="100%" (a string), causing incorrect aspect ratio classes (wp-embed-aspect-21-9) to be applied, which creates the extra whitespace.
Note
After the fix, album embeds will display in a stacked layout (tracklist below art) instead of the previous compact side-by-side layout. This is expected, Spotify switches layouts based on height, and the compact layout was a side effect of the incorrect squishing.
Screencast After fix:
https://github.com/user-attachments/assets/1d728675-3b33-4fab-b4b3-700031716eff
However there is one concern, as we are skipping aspect-ratio calculation completely, If height of iframe is too large (~4000px) which is very rare case, then it will break layout on website so if we take this concern into consideration then we have to look for alternative approach.
I've implemented a fix for this issue that addresses both the whitespace problem and the edge case.
The fix detects when iframe dimensions use percentage values (like Spotify's width="100%"):
For normal Spotify embeds (width="100%" with reasonable height ≤800px):
- Skips aspect ratio calculation entirely
- Allows the embed to render at its natural dimensions
- Eliminates the whitespace issue
For edge cases (percentage width/height with very large dimensions >800px):
- Applies a constraining 9:16 vertical aspect ratio
- Prevents potential UI breaks while maintaining a reasonable appearance
A Flickr embed had similar aspect ratio issues, which were fixed in #73902.