Skip to content
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

Merged
merged 3 commits into from
Jun 15, 2022

Conversation

manzurahammed
Copy link
Contributor

This PR fixed the issue of #41308

@manzurahammed manzurahammed requested a review from ajitbohra as a code owner May 25, 2022 20:14
@github-actions
Copy link

👋 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.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 25, 2022
@gziolo gziolo added [Type] Bug An existing feature does not function as intended [Package] Block library /packages/block-library [Block] Avatar Affects the Avatar Block labels May 25, 2022
@gziolo gziolo changed the title Fix JS Error in Avatar Block Block Library: Fix JS Error in Avatar Block May 25, 2022
@rudlinkon
Copy link

@ajitbohra please review it.

return {
src: defaultAvatar,
minSize: 24,
maxSize: 96,
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {
Copy link
Contributor

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, great findings.

Copy link

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

Copy link
Contributor

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 😄

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.

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.

Copy link
Contributor

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 😄

Copy link

@rudlinkon rudlinkon Jun 10, 2022

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?

Copy link
Contributor Author

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

Copy link
Contributor

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 🤞

@manzurahammed
Copy link
Contributor Author

@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
@ockham ockham force-pushed the fix/avatar-block-js-error branch from fa6aeb8 to 8e33093 Compare June 14, 2022 20:17
Copy link
Contributor

@cbravobernal cbravobernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cbravobernal cbravobernal merged commit 177e774 into WordPress:trunk Jun 15, 2022
@cbravobernal cbravobernal added the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Jun 15, 2022
@github-actions github-actions bot added this to the Gutenberg 13.5 milestone Jun 15, 2022
adamziel pushed a commit that referenced this pull request Jun 21, 2022
* 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
@adamziel
Copy link
Contributor

I just cherry-picked this PR to the wp/6.0 branch to get it included in the next release: 0730c96

@adamziel adamziel removed the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Jun 21, 2022
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Avatar Affects the Avatar Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

8 participants