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

Declare event listeners as non-passive to remove browser warnings #4437

Merged
merged 4 commits into from
Mar 4, 2021

Conversation

ebonow
Copy link
Collaborator

@ebonow ebonow commented Feb 8, 2021

Problem:

Issue: non-passive event listener in scroll blocking events #2729

Chrome issues console warnings when adding some event listeners without declaring them as passive. Three of these warnings present themselves in a non-mobile view when opening the menu.

Screen Shot 2021-02-08 at 8 13 03 AM

Resolution:

By explicitly setting passive is false, Chrome will no longer show this warning in the console.

@changeset-bot
Copy link

changeset-bot bot commented Feb 8, 2021

🦋 Changeset detected

Latest commit: 7891f32

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-select Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ebonow ebonow linked an issue Feb 8, 2021 that may be closed by this pull request
@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 8, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7891f32:

Sandbox Source
react-codesandboxer-example Configuration

@ebonow ebonow added this to the 4.2 milestone Feb 8, 2021
Copy link
Owner

@JedWatson JedWatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look and there is a backwards compatibility concern here with older browsers -- https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection

Off the top of my head I'm not confident that this wouldn't cause a problem for browsers that react-select supports in the wild, so unless we wait for a major release, I'd be more comfortable if we added the compatibility check in here.

(note: with the next major version we should really clarify our browser support so stuff like this doesn't come up again! I think evergreen is fair these days, and IE is dead, but when we rewrote for v2 IE11 was still actually a target for Atlassian so unless someone knows other reasons it wouldn't still work on IE, it may, and if so people using it may also be relying on that 🤷‍♂️)

@ebonow
Copy link
Collaborator Author

ebonow commented Feb 9, 2021

@JedWatson Thanks for the heads up on that and I did miss that consideration, though I did see this was something that had been explored before.

This may be a case where we'd like to include the polyfill and consider removing it for some major release. I understand the warnings are fairly innocuous, but ultimately it reflects poorly on on the devs using react-select to have Chrome console spamming 3 warning messages every time a menu is opened.

@ebonow
Copy link
Collaborator Author

ebonow commented Feb 10, 2021

@JedWatson , I added a polyfill to support legacy browsers.

Also in regards to these...

// all the if statements are to appease Flow 😢
if (typeof el.addEventListener === 'function') {
el.addEventListener('wheel', onWheel, notPassive);
}
if (typeof el.addEventListener === 'function') {
el.addEventListener('touchstart', onTouchStart, notPassive);
}
if (typeof el.addEventListener === 'function') {
el.addEventListener('touchmove', onTouchMove, notPassive);
}

I know I am fairly new to Flow, but the events are being attached directly to the DOM, so wouldn't they be actual Wheel/Touch events and not synthetic events?

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.

non-passive event listener in scroll blocking events
2 participants