Chrome have decided to break the web by assuming that touch/wheel events are passive unless you explicitly pass passive: false. Aside from philosophical concerns about breaking older apps that are no longer maintained, this makes life harder for Svelte, since there's no way to declaratively state that an event listener should be non-passive:
<!-- we can state that we're passive... -->
<div on:touchstart|passive={handler}>...</div>
<!-- or we can leave it ambiguous... -->
<div on:touchstart={handler}>...</div>
<!-- but there's no option for 'i need to use preventDefault' -->
Possible solution: add an active modifier:
<!-- signals that `handler` calls `event.preventDefault()` -->
<div on:touchstart|active={handler}>...</div>
I'm a fan of the active modifier. This is a modifier that will be a pain to add independently to each event, but for those times where it is necessary for specific use-cases involving cancelable touch events, it would be useful to have it.
Adding an extra use-case: I have a scroll listener that _needs_ to be synchronous so I need to specify passive: false.
Small note: rather than active as the modifier name, nonpassive would be more explicit of what it is doing
I need this in order to move an element by touch while preventing scrolling in sapper.
Due to "Unable to preventDefault inside passive event listener due to target being treated as passive."
I vote for nonpassive
Oops, I was able to solve my issue with touch-action:none
Version 3.27.0 now has a |nonpassive event modifier that can be used to pass passive: false to addEventListener.
Most helpful comment
Adding an extra use-case: I have a scroll listener that _needs_ to be synchronous so I need to specify
passive: false.Small note: rather than
activeas the modifier name,nonpassivewould be more explicit of what it is doing