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: addEventListenerWrap param target may be nullish #445

Merged
merged 1 commit into from
May 29, 2023

Conversation

zerosrat
Copy link
Contributor

@zerosrat zerosrat commented May 29, 2023

When target is nullish, it will throw TypeError: Cannot read properties of null (reading 'addEventListener').
So I add the optional chaining to avoid the error.

@zombieJ

@vercel
Copy link

vercel bot commented May 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
util ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2023 8:36am

@zombieJ
Copy link
Member

zombieJ commented May 29, 2023

It's strange to provide empty as target. But this code seems fine.

@zombieJ zombieJ merged commit 615d435 into react-component:master May 29, 2023
8 checks passed
@zerosrat
Copy link
Contributor Author

zerosrat commented May 30, 2023

It's strange to provide empty as target. But this code seems fine.

The origin issuse is from stickyScrollBar of rc-table. The code is as follows:

React.useEffect(function () {
    var onMouseUpListener = addEventListener(document.body, 'mouseup', onMouseUp, false);
}, [])

When invoking addEventListener in useEffect, document.body is null. Add null check can avoid the error log, but it still cannot add listener as expected.

@zombieJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants