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

Compatibility Issues Between "React" and "React-OnClickOutside" Libraries #396

Merged
merged 2 commits into from May 10, 2024

Conversation

OrMeirchak
Copy link
Contributor

Fix for the problem where the event handler was being called even though it was registered after the event was created

We will check whether the event was created before the registration of the component.
In that case we will ignore the event.
@@ -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;
Copy link
Owner

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.

Copy link

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?

Copy link
Owner

@Pomax Pomax May 9, 2024

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?

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.

Copy link
Owner

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.

Copy link
Owner

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.

@Pomax Pomax merged commit 8178f3a into Pomax:master May 10, 2024
@Pomax
Copy link
Owner

Pomax commented May 10, 2024

published v6.13.1

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

3 participants