-
Notifications
You must be signed in to change notification settings - Fork 25
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
Prevent unnecessary event listeners #72
Comments
This does not appear to be an issue because of this behavior of Event Listeners:
The function being called is a named function, so they have the same signature and the subsequent attempts to create an event listener are discarded. |
|
Very likely. From the same source as the above comment:
This could easily be solved by simply moving the function definition into the outer scope, or even to a separate file for import. |
Okay, go ahead and find an optimal way to solve the issue in a new PR. |
In trying a number of approaches to solving this issue I have encountered a few problems, here is what I have tried and the issues I have encountered: My first approach to creating a completely stable signature for the function was to create it in a separate file as a utility function and export it. This meant a loss of context for many values the function used, but they could be passed along to it as arguments. That approach looked something like:
The issue I encountered with this approach is that there is no way to pass along the arguments it needs (That I am currently aware of) when it is called by the event listener, except to create a callback function that calls it with those arguments, like so:
But this just recreates the same problem we are trying to solve by importing the function from another file, since the callback function is now either anonymous and never has a stable signature, or a named function that gets redefined every time the useEffect is fired. My other approach was simply moving |
Would |
Maybe first we need to come up with a way to verify whether or not our concerns are valid. Have you been able to show definitively that we're adding duplicate event listeners? |
I was actually pretty much able to verify the opposite. While |
Okay, then I assume we can safely close this issue then? |
I think that would be fine, I don't see any evidence of performance issues as things stand. |
There are indications that the useEffect on line 52 could be generating extra click event listeners every time the menu open or closes. This should be researched to determine if it is the case, and a PR opened to erect the issue.
The text was updated successfully, but these errors were encountered: