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

Incompatible with passive event listeners #1217

Closed
rjgotten opened this issue Sep 28, 2016 · 14 comments
Closed

Incompatible with passive event listeners #1217

rjgotten opened this issue Sep 28, 2016 · 14 comments

Comments

@rjgotten
Copy link

When used with recent Chrome builds that support passive event listeners, touch interaction leads to a massive spew of errors:

Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/5093566007214080

PhotoSwipe needs to detect passive event listener support and explicitly register its document level touch handlers with a passive: false option.

@dimsemenov
Copy link
Owner

dimsemenov commented Sep 28, 2016

I've heard that Blink is planning to make {passive:true} by default, WICG/interventions#18

What's the lightest way to detect passive events? Anything more compact than:

var supportsPassive = false;
if(Object.defineProperty) {
    var opts = Object.defineProperty({}, 'passive', {
        get: function() {
            supportsPassive = true;
        }
    });
    window.addEventListener('test', null, opts);
}

?

@rjgotten
Copy link
Author

That's the lightest way to do it, as far as I'm aware.

@dtapuska
Copy link

dtapuska commented Sep 28, 2016

It looks like you use pointer events why aren't you checking window.PointerEvent and using the MS specific value instead (navigator.pointerEnabled).

That would likely mitigate it because pointer events is going out before the passive event listener intervention.

@dimsemenov
Copy link
Owner

@dtapuska, it's a good point, I plan to drop msPointerEnabled and check for just window.PointerEvent in the next major release, usage of IE10 is very low and it can always fall back to mouse events.

@dtapuska
Copy link

FYI... Chrome pointer events are enabled in beta, dev and canary. The intervention is only enabled in canary and dev.

@RByers
Copy link

RByers commented Feb 17, 2017

Sorry for the trouble, this is now a breaking change in Chrome 56 to improve scroll performance. You can probably fix this by adding an appropriate touch-action CSS rule.

@capuski
Copy link

capuski commented Mar 12, 2017

I'm still having problems with this issue. Because of this, when you use photoswipe on mobile devices, when you swipe to close a image, the page jumps to the top, really bad =/

@rjgotten
Copy link
Author

rjgotten commented Mar 13, 2017

@RByers
Photoswipe already adds a touch-action:none to its top element that contains the component's entire UI.
It is not a magical cure-all for all issues related to Chrome's misguided scroll-performance intervention.

You cannot get rid of the event.preventDefault() calls here. Because for browsers that don't support touch-action in conjunction with touch events, you must use event.preventDefault() to cut out native touch behavior. That includes Firefox 51 and lower, because touch-action only became enabled by default from version 52 onwards, and all current and old versions of Safari, which support only the auto and manipulation values at best, which falls short of supporting all possible UI interaction patterns.

Even if touch-action can be used to remove the functional issue of native touch behavior continuing to run in Chrome, that will still continue to generate massive amounts of console warning spam:

Unable to preventDefault inside passive event listener due to target being treated as passive

The only proper way to fix this cross-browser, including getting Chrome to shut its trap, is to employ a bit of intermediary code around libraries' addEventListener calls which detects passive event handler support and sends an explicit passive:false for those browsers that support it.

@RByers
Copy link

RByers commented Apr 3, 2017

Adding touch-action: none without changing any of the existing code that calls preventDefault should absolutely be a "magical cure-all". Chrome's console warning is disabled as soon as we detect touch-action is used at all (i.e. it errs on the side of under-warning, not over-warning). If you can provide a repro case that doesn't match what I've described here, we'd treat it as a high priority bug and investigate / fix ASAP.

@rjgotten
Copy link
Author

rjgotten commented Apr 3, 2017

Adding touch-action: none without changing any of the existing code that calls preventDefault should absolutely be a "magical cure-all". Chrome's console warning is disabled as soon as we detect touch-action is used at all

That makes it a magical cure-all only for Chrome, and that's only in the best case scenario.

It's wholy possible and often very desirable to cancel only part of the native behavior and thus the touch-action value continues to need tweaking and case-by-case solving. Just dumping in a touch-action:none and calling it a day does not suffice.

You've also done nothing to address the problems with iOS Safari which supports only a limited subset of touch-action values and which would all but require the infusion of some form of unholy marriage of touch-action and event.preventDefault() to keep everything working.

@basakil
Copy link

basakil commented Nov 6, 2017

Added (& tried many combinations of) 'touch-action: none;' everywhere from html to holder div, but error deluge did not cease in any case. Sometimes the list does not respond to dragging, but most of the time works fine even if it does is slower. Error Lines are 612 & 1501 consecutively. Any hope for a fix or recommendation of another cure?

@dimsemenov
Copy link
Owner

Sometimes the list does not respond to dragging

@basakil, which list? This is PhotoSwipe repo, and it already has touch-action:none on its root element, so preventDefault won't make any difference in browsers that support touch-action.

@basakil
Copy link

basakil commented Nov 7, 2017

Oh maan! I thought this was the Sortable group... Sorry.

@dimsemenov
Copy link
Owner

fixed by v5.0

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

No branches or pull requests

6 participants