Skip to content

Block Library: Show fallback label in MediaControl when filename is empty#76888

Merged
Mamaduka merged 2 commits intoWordPress:trunkfrom
jigangz:fix/media-control-fallback-label
Mar 30, 2026
Merged

Block Library: Show fallback label in MediaControl when filename is empty#76888
Mamaduka merged 2 commits intoWordPress:trunkfrom
jigangz:fix/media-control-fallback-label

Conversation

@jigangz
Copy link
Copy Markdown
Contributor

@jigangz jigangz commented Mar 29, 2026

What?

Show a fallback label in MediaControl when getFilename() returns an empty string.

Why?

When a media URL does not end with a recognizable filename (e.g., server-generated images like https://api.openverse.org/v1/images/.../thumb/), getFilename() returns an empty string. This causes the MediaControl label to render as blank in the inspector panel.

How?

Add a fallback to emptyLabel when getFilename() returns a falsy value:

// Before
mediaUrl ? getFilename( filename ) : emptyLabel

// After
mediaUrl ? getFilename( filename ) || emptyLabel : emptyLabel

This keeps the fix minimal in MediaControl as suggested by @Adi-ty.

Testing Instructions

  1. Add an Image block
  2. Set the image URL to a server-generated URL without a file extension (e.g. https://api.openverse.org/v1/images/e945bba3-4817-468f-8740-57d326de5b6d/thumb/)
  3. Check the inspector panel — the label should now show "Media" instead of being blank

Fixes #76882

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 29, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jigangz <jigangz@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: Adi-ty <iamadisingh@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added [Package] Block library /packages/block-library First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository labels Mar 29, 2026
@github-actions
Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @jigangz! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@Mamaduka Mamaduka added the [Type] Bug An existing feature does not function as intended label Mar 29, 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.

Thanks, @jigangz!

While tests are more than welcome for bug fixes, I don't think this simple case needs one.

jigangz added 2 commits March 29, 2026 08:14
…mpty

When a media URL does not end with a recognizable filename (e.g.,
server-generated images like `https://api.example.com/.../thumb/`),
`getFilename()` returns an empty string. This caused the MediaControl
label to render as blank in the inspector panel.

Add a fallback to `emptyLabel` when `getFilename()` returns a falsy
value, so the control always shows a meaningful label.

Fixes WordPress#76882
@jigangz jigangz force-pushed the fix/media-control-fallback-label branch from 0ce9ab7 to def0b1b Compare March 29, 2026 15:14
Copy link
Copy Markdown
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks, @jigangz!

@Mamaduka Mamaduka merged commit a725368 into WordPress:trunk Mar 30, 2026
40 checks passed
@github-actions github-actions bot added this to the Gutenberg 22.9 milestone Mar 30, 2026
adamsilverstein pushed a commit that referenced this pull request Mar 31, 2026
…mpty (#76888)

Co-authored-by: jigangz <jigangz@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: Adi-ty <iamadisingh@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
ObliviousHarmony pushed a commit that referenced this pull request Apr 1, 2026
…mpty (#76888)

Co-authored-by: jigangz <jigangz@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: Adi-ty <iamadisingh@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block Library: MediaControl should show fallback label

2 participants