-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Site Logo Block: Fix non-admin users seeing zero character #65010
Conversation
Size Change: +2 B (0%) Total Size: 1.78 MB
ℹ️ View Unchanged
|
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.
Good catch! Works as expected. LGTM
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -423,7 +423,7 @@ export default function LogoEdit( { | |||
context: 'view', | |||
} ); | |||
const _isRequestingMediaItem = | |||
_siteLogoId && | |||
!! _siteLogoId && |
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.
Great catch, thanks for spotting it 🥇 LGTM
Thank you everyone for the reviews ❤️ |
Follow-up #64919
What?
This PR prevents non-admins from seeing the string "0" in the Site Logo block if no logo is set.
Why?
This PR only contains a two-character change, but I'll explain why step by step.
Here we get the site data. If the site logo has not yet been applied and we are not an non-admin user,
siteData?.site_logo
will have0
:gutenberg/packages/block-library/src/site-logo/edit.js
Lines 416 to 418 in 18164f0
Next, we check whether the media is being retrieved.
_siteLogoId
is0
, a falsy value. Due to the rules of logical operators, a short-circuit evaluation is performed and the value on the left-hand side is returned unchanged, so_isRequestingMediaItem
has a0
value. Ideally, the left-hand side should be converted to a Boolean value here:gutenberg/packages/block-library/src/site-logo/edit.js
Lines 425 to 430 in 18164f0
As a result,
isLoading
here will have the following formula. Since the left side does not evaluate to a match, the right side, which is0
, is returned:gutenberg/packages/block-library/src/site-logo/edit.js
Line 538 in 18164f0
Here the spinner is rendered:
gutenberg/packages/block-library/src/site-logo/edit.js
Lines 659 to 665 in 18164f0
Since
isLoading
is0
, it short-circuits and expands to this:How?
Since
_isRequestingMediaItem
is expected to be a boolean value, I explicitly converted_siteLogoId
in the conditional expression to a boolean type. This problem was inherently there, but thankfully it was brought to light by #64919.Testing Instructions
0
will not be displayed.