-
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
Block Library: Fix JS Error in Avatar Block #41354
Block Library: Fix JS Error in Avatar Block #41354
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @manzurahammed! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
@ajitbohra please review it. |
return { | ||
src: defaultAvatar, | ||
minSize: 24, | ||
maxSize: 96, |
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 the PR!
Here, maxSize will be different than the value we got from getAvatarSizes( sizes )
function getAvatarSizes( sizes ) {
const minSize = sizes ? sizes[ 0 ] : 24;
const maxSize = sizes ? sizes[ sizes.length - 1 ] : 96;
const maxSizeBuffer = Math.floor( maxSize * 2.5 );
return {
minSize,
maxSize: maxSizeBuffer,
};
}
So if Avatar is disabled, it will appear with no errors, but with different size maximum value than if Avatar is enabled on discussion settings.
src: defaultAvatar, | ||
minSize: 24, | ||
maxSize: 96, | ||
alt: authorDetails.name, |
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.
alt: authorDetails.name, | |
alt: authorDetails | |
? // translators: %s is the Author name. | |
sprintf( __( '%s Avatar' ), authorDetails?.name ) | |
: __( 'Default Avatar' ), |
@@ -76,14 +76,23 @@ export function useUserAvatar( { userId, postId, postType } ) { | |||
}, | |||
[ postType, postId, userId ] | |||
); | |||
const defaultAvatar = useDefaultAvatar(); | |||
if ( authorDetails && ! authorDetails?.avatar_urls ) { | |||
return { |
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.
If we do a return if this condition applies, we may skip some checks we make after, assuming that sizes or avatar URLs may not be null on the code after this return.
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.
yes, great findings.
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.
Agreed with @c4rl0sbr4v0
Good Job @manzurahammed
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.
Let me know if you need any help here 😄
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.
@c4rl0sbr4v0 please discuss it with other reviewers and make it resolved, thank you for your effort.
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, @c4rl0sbr4v0 for your information. will inform you after doing this.
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.
👋 Hey @rudlinkon, any updates on this? 😄 I'd like to get this merged soon so we can include it in WP 6.0.1.
If you don't find the time currently to apply the changes that @c4rl0sbr4v0 suggested, that's fine -- just let us know and we'll take care of them 😄
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.
@ockham thank you for your reminder, actually, I'm a little bit busy now. @manzurahammed brother could you have a look please?
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.
Hi, @ockham Could you check, please.
I have pushed a new commit
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 @rudlinkon and @manzurahammed!
Looking pretty good! I just rebased to fix unit tests which were failing due to an outdated dependency. Let's see if they pass now 🤞
@c4rl0sbr4v0 thanks for the tip 😁 done in 579698f |
Use defaultAvatar image instead of original image of user for prevent js error.This error occurred when Display Avatar unchecked from Setting->Discussion
fa6aeb8
to
8e33093
Compare
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.
LGTM!
* Fix JS Error in Avatar Block Use defaultAvatar image instead of original image of user for prevent js error.This error occurred when Display Avatar unchecked from Setting->Discussion * fix the author name issue * Fix JS linting issue
I just cherry-picked this PR to the wp/6.0 branch to get it included in the next release: 0730c96 |
This PR fixed the issue of #41308