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
Compatibility Issues Between "React" and "React-OnClickOutside" Libraries #396
Conversation
We will check whether the event was created before the registration of the component. In that case we will ignore the event.
Update index.js
@@ -163,6 +164,8 @@ export default function onClickOutsideHOC(WrappedComponent, config) { | |||
|
|||
handlersMap[this._uid] = event => { | |||
if (this.componentNode === null) return; | |||
|
|||
if (this.initTimeStamp > event.timeStamp) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this feels like it's fixing a race condition. This function should not be able to trigger before the constructor runs, so while this might fix the symptom it's probably better to track down the underlying cause. Thanks to it being a long weekend here in Canada, I should hopefully have time today to dig into this a little.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there any better solution discussed for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the counter question would be that modern React, having gone all-in on hooks (whether we like it or not) kind of... removed the need for this hoc. So as a sincere question: does anyone still need this fixed, rather than just updating to the current version of React and useEffecting outside-click handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are working on an oldcodebase where its not feasible to migrate to hooks easily, So it would be great if we can fix a solution for the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hooks are over 5 years old at this point, I would strongly encourage you to consider getting on board with modern Reactg if you want to keep using it (understanding full well that's almost certainly not your call to make).
I'll merge this in, but given React's trajectory, this will be a bandaid at best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if this HoC is that important to your codebase, consider taking the first paragraph of the README to heart and giving back any way you can.
published v6.13.1 |
Fix for the problem where the event handler was being called even though it was registered after the event was created