Skip to content

Commit 5dbe763

Browse files
authored
fix: don't make wheel events passive by default (#13322)
This was done previously to align with browser behavior, but the browser behavior actually only makes them passive on window/document/body. Since wheel events are not delegated, we can revert their passive-by-default setting. Closes #13318 For touchstart/touchmove we're not changing it because these events are delegated, which means they happen a lot more often on a target higher up the tree, which may cause jank.
1 parent 0ef14b5 commit 5dbe763

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.changeset/new-baboons-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: don't make wheel events passive by default

documentation/docs/02-template-syntax/02-basic-markup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Because events are just attributes, the same rules as for attributes apply:
112112

113113
Timing-wise, event attributes always fire after events from bindings (e.g. `oninput` always fires after an update to `bind:value`). Under the hood, some event handlers are attached directly with `addEventListener`, while others are _delegated_.
114114

115-
When using `onwheel`, `onmousewheel`, `ontouchstart` and `ontouchmove` event attributes, the handlers are [passive](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#using_passive_listeners) to align with browser defaults. This greatly improves responsiveness by allowing the browser to scroll the document immediately, rather than waiting to see if the event handler calls `event.preventDefault()`.
115+
When using `ontouchstart` and `ontouchmove` event attributes, the handlers are [passive](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#using_passive_listeners) for better performance. This greatly improves responsiveness by allowing the browser to scroll the document immediately, rather than waiting to see if the event handler calls `event.preventDefault()`.
116116

117117
In the very rare cases that you need to prevent these event defaults, you should use [`on`](https://svelte-5-preview.vercel.app/docs/imports#svelte-events) instead (for example inside an action).
118118

packages/svelte/src/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,16 @@ export function is_dom_property(name) {
222222
return DOM_PROPERTIES.includes(name);
223223
}
224224

225-
const PASSIVE_EVENTS = ['wheel', 'mousewheel', 'touchstart', 'touchmove'];
225+
/**
226+
* Subset of delegated events which should be passive by default.
227+
* These two are already passive via browser defaults on window, document and body.
228+
* But since
229+
* - we're delegating them
230+
* - they happen often
231+
* - they apply to mobile which is generally less performant
232+
* we're marking them as passive by default for other elements, too.
233+
*/
234+
const PASSIVE_EVENTS = ['touchstart', 'touchmove'];
226235

227236
/**
228237
* Returns `true` if `name` is a passive event

0 commit comments

Comments
 (0)