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

[Error] Unable to preventDefault inside passive event listener invocation. #136

Closed
ajaypillay opened this issue May 29, 2021 · 14 comments · Fixed by #141
Closed

[Error] Unable to preventDefault inside passive event listener invocation. #136

ajaypillay opened this issue May 29, 2021 · 14 comments · Fixed by #141

Comments

@ajaypillay
Copy link

Hi, my browser's console keeps throwing this error, when all I have done is embedded <HexColorPicker color={color} onChange={setColor} /> in a functional component.

I tried setting touch-action: none to all parent divs up to body but the error is still being thrown. That being said, the color picker works fine on desktop and mobile, it's just that I'm not sure why this error is being thrown.

Any suggestions on remedying this?

This is a great library by the way! I avoided starting off with react-color because it seems outdated and has many open issues, while this is far more recent and modernized. Thank you for this.

@omgovich
Copy link
Owner

omgovich commented May 30, 2021

Hi! I guess the problem is in your setColor function.

I assume it looks like this:

const setColor = (e) => {
  e.preventDefault()
  console.log(e.target.value)
}

But react-colorful doesn't return an event object in the handler. So it has to be:

const setColor = (value) => {
  console.log(value)
}

Please check your event hander and let me know if the problem is there.

@ajaypillay
Copy link
Author

Unfortunately my code is exactly as per the Readme.

import { HexColorPicker } from "react-colorful";
const Component = () => {
  const [color, setColor] = useState("#aabbcc");
  return <HexColorPicker color={color} onChange={setColor} />;
};

I've tested it on a blank page with no other components or touch events going on, and I can't seem to figure out why this is happening.

@omgovich
Copy link
Owner

Could you please provide an error stack trace? Just screenshot dev tools console for example.

@omgovich
Copy link
Owner

Not sure that error is inside of react-colorful since we don't use passive event listeners 🤔

@ajaypillay
Copy link
Author

ajaypillay commented May 30, 2021

I'm trying to debug this a little further. I'm running Meteor, and I think something is conflicting with this.
image
This is the beginning of the line the error is thrown.
image
And this is specifically where the error is.
image
When I include the package/component itself, no error is thrown. This error is thrown only upon interacting with the component (as it should be).

@omgovich
Copy link
Owner

I'll try to create a Meteor app and run react-colorful there. Let you once I have some results.

@ajaypillay
Copy link
Author

Thank you very much for the help.

@omgovich
Copy link
Owner

omgovich commented May 31, 2021

Hi! What version of react-dom do you use in your project?
Seems like it's relevant to this issue facebook/react#19651 and having 17.0.1+ should help.

@ajaypillay
Copy link
Author

My react-dom version is 17.0.2, which is the latest version right now.

@omgovich
Copy link
Owner

Got it. Seems like the source of the problem is that touchstart event is now passive by default in the browsers.
Will try to find a workaround.

@ajaypillay
Copy link
Author

Got it. Seems like the source of the problem is that touchstart event is now passive by default in the browsers.
Will try to find a workaround.

Interesting, thank you for the fix! Sincerely appreciated.

@omgovich
Copy link
Owner

Please try the new v5.2.2 and let me know the warning is still present.

@ajaypillay
Copy link
Author

Just tested it and the warning isn't being thrown anymore, and it still works perfectly fine.

@omgovich
Copy link
Owner

Nice! Thanks for pointing out the bug and best of luck with your project)

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 a pull request may close this issue.

2 participants