-
Notifications
You must be signed in to change notification settings - Fork 93
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
useEventListener
does not check to see if event target is valid, which can break SSR
#978
Comments
How should we go about fixing this? Could it be just a simple I attempted this, but found that I couldn't write a test which would reveal this bug, since in the SSR tests This begs the question: how would we move the
Is this even possible (disclosure: I have little experience with SSR)? |
Doesn't that actually test the bug exactly? Assuming we don't have My question is, do we have |
We provide The hook itself uses the provided event target only inside of an Seems to me there is no bug here at all - or I am totally wrong and learn a lesson on SSR! |
This makes me wonder, should we then perhaps support giving |
Any more thoughts on this? If not, I think this issue could be closed. Would love to see the issue list shrink a bit more! |
As figured - types has changed and there is no more issues with global this, but |
It has to be done by user, since user evaluates the Making target optional and placed as last call parameter will break arguments inferrence and is kinda weird. nextjs users shall use |
Just to note, this hook could also probably be reimplemented with React 18's |
@ArttuOll yes, but that does not solve the issue with attempt to pass |
Yeah, you're totally right. That was just a quick thought. |
This is bad bad design with inobvious logic, we definely wont follow react-use's way.
It is not necessary.
Not all SSR engines have The reason |
The only thing we can do is to add notification that SSR users have to consult the docs of their SSR engine to safely reference the |
I might have time for this next week. |
Prior Issues
Are there any existing issues or PRs that relate to this problem? If so, link them here.
What is the current behavior?
As reported by damntv on Discord,
useEventListener
currently does not check the event target is valid, which can cause an error if you are trying to targetwindow
,document
, etc. during SSR.Steps to Reproduce
Throws an error when server side rendered because the
window
is not defined on the server.What is the expected behavior?
@react-hookz/web
should check to make sure the event target is valid, at least on server side, before trying to set the event.Environment Details
@react-hookz/web
version: 16.0.0react
version:react-dom
version:typescript
version:The text was updated successfully, but these errors were encountered: