-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Site Logo Block: Fix non-admin users seeing zero character #65010
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
Conversation
|
Size Change: +2 B (0%) Total Size: 1.78 MB
ℹ️ View Unchanged
|
akasunil
left a comment
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. |
| } ); | ||
| 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_logowill 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.
_siteLogoIdis0, 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_isRequestingMediaItemhas a0value. 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,
isLoadinghere 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
isLoadingis0, it short-circuits and expands to this:How?
Since
_isRequestingMediaItemis expected to be a boolean value, I explicitly converted_siteLogoIdin the conditional expression to a boolean type. This problem was inherently there, but thankfully it was brought to light by #64919.Testing Instructions
0will not be displayed.