-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
What?
Closes #55086
Fix a bug where when setting an initial image to the Cover block, the overlay color is always set to
#FFF
when it should be an average color of the uploaded image.Related discussion: https://wordpress.slack.com/archives/C02QB2JS7/p1696833027605459
How?
The
onSelectMedia
handler is called twice:url
(blob) andtype
fields. Thetype
field isimage
so the average background color is calculated and applied. However, this is only visible for a split second, becausetype
field'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_type
field in the uploaded media data. This seems to rectify the problem.Testing Instructions
trunk