Cover: Fix media type check in the onSelectMedia hook - #55168
Conversation
|
Size Change: +26 B (0%) Total Size: 1.65 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 659ba57. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6459760901
|
There was a problem hiding this comment.
Thanks for hunting this issue down @WunderBart! Glad to see the end to end tests are somewhat working.
I followed the testing instructions. Against trunk I can see the bug clearly, and it's also more obvious when you compare what happens when adding an existing media library image vs uploading.
On this PR, everything is resolved.
Code looks good and makes sense to me.
Tests the regression from PR #55168 where selecting an image from the Media Library (media_type: 'image') didn't trigger overlay color auto-detection, falling back to the default white color instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The media library test for PR #55168 doesn't actually catch the regression when the fix is reverted. The bug is in the upload path (second onSelectMedia callback has type: "attachment"), not the media library path (which provides type: "image"). The existing "dims background image down by 50%" test already catches this regression. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
What?
Closes #55086
Fix a bug where when setting an initial image to the Cover block, the overlay color is always set to
#FFFwhen it should be an average color of the uploaded image.Related discussion: https://wordpress.slack.com/archives/C02QB2JS7/p1696833027605459
How?
The
onSelectMediahandler is called twice:url(blob) andtypefields. Thetypefield isimageso the average background color is calculated and applied. However, this is only visible for a split second, becausetypefield's value is nowattachment. Because the average background color is being calculated only for images, it is now failing and the color is reset to the default value.To address this inconsistency, I've modified the condition to also check the
media_typefield in the uploaded media data. This seems to rectify the problem.Testing Instructions
trunk