Skip to content

Commit 54ffef5

Browse files
committed
fix: robustify initial scroll value detection when scroll is smooth
- the previous assumption was wrong: browser don't fire a scroll event initially when the scroll isn't smooth - the previous logic wasn't using the "is scrolling now" logic which meant the render effect fired immediately after, causing smooth scrolling to start too late to be overridden adjusted the comment and reused the scroll handler function to guard against the race condition fixes #11623
1 parent d1a14ef commit 54ffef5

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

.changeset/tough-tomatoes-explain.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: robustify initial scroll value detection when scroll is smooth

packages/svelte/src/internal/client/dom/elements/bindings/window.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,8 @@ export function bind_window_scroll(type, get_value, update) {
4949
}
5050
});
5151

52-
// Browsers fire the scroll event only if the scroll position is not 0.
53-
// This effect is (almost) guaranteed to run after the scroll event would've fired.
54-
effect(() => {
55-
var value = window[is_scrolling_x ? 'scrollX' : 'scrollY'];
56-
if (value === 0) {
57-
yield_updates(() => update(value));
58-
}
59-
});
52+
// Browsers don't fire the scroll event for the initial scroll position when scroll style isn't set to smooth
53+
effect(target_handler);
6054

6155
render_effect(() => {
6256
return () => {

0 commit comments

Comments
 (0)