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

fix console error TypeError can't read properties of null in Hoverable.js #19488

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Hoverable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Hoverable extends Component {
onMouseEnter={() => this.setIsHovered(true)}
onMouseLeave={() => this.setIsHovered(false)}
onBlur={(el) => {
if (this.wrapperView.contains(el.relatedTarget)) {
if (!_.isNull(this.wrapperView) && this.wrapperView.contains(el.relatedTarget)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@ahmedGaber93 Should we do this in other onBlur too?

onBlur: (el) => {
if (!this.wrapperView.contains(el.relatedTarget)) {
this.setIsHovered(false);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mollfpr yes, we should.
I think we need to check null here also to prevent this error in all places
if (!_.isNull(this.wrapperView) && !this.wrapperView.contains(el.relatedTarget))
do you agree?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ahmedGaber93 Sounds good to me!

Copy link
Contributor

Choose a reason for hiding this comment

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

@ahmedGaber93 On second thought, looking and the original condition !this.wrapperView.contains(el.relatedTarget), so that's mean null this.wrapperView is also true?

I'm not sure to understand the condition; it's either

  1. !_.isNull(this.wrapperView) && !this.wrapperView.contains(el.relatedTarget)
  2. _.isNull(this.wrapperView) || !this.wrapperView.contains(el.relatedTarget)

What do you guys think?

Copy link
Contributor Author

@ahmedGaber93 ahmedGaber93 May 24, 2023

Choose a reason for hiding this comment

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

@mollfpr I think the two conditions will prevent call contains from null this.wrapperView.
But even though we don't have any UI visual issues, I think the second condition logic is better because it will set isHovered to fallback false.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ahmedGaber93 Let's go with the second logic then! Sorry for the hustle 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mollfpr are you mean use !_.isNull(this.wrapperView) && in the two places
or remove it from the second place here.

onBlur: (el) => {
if (!this.wrapperView.contains(el.relatedTarget)) {
this.setIsHovered(false);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@ahmedGaber93 Only for remove it from this.

if (!this.wrapperView.contains(el.relatedTarget)) { 
         this.setIsHovered(false); 
     } 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mollfpr removed, you can review now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any problem if just adding this?

-                   if (this.wrapperView.contains(el.relatedTarget)) {
+                   if (this.wrapperView && this.wrapperView.contains(el.relatedTarget)) {

return;
}
this.setIsHovered(false);
Expand Down