fix: robustify initial scroll value detection when scroll is smooth (#11802)

- 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
pull/11808/head
Simon H 1 year ago committed by GitHub
parent d1a14ef147
commit ba6697d31d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: robustify initial scroll value detection when scroll is smooth

@ -49,14 +49,8 @@ export function bind_window_scroll(type, get_value, update) {
}
});
// Browsers fire the scroll event only if the scroll position is not 0.
// This effect is (almost) guaranteed to run after the scroll event would've fired.
effect(() => {
var value = window[is_scrolling_x ? 'scrollX' : 'scrollY'];
if (value === 0) {
yield_updates(() => update(value));
}
});
// Browsers don't fire the scroll event for the initial scroll position when scroll style isn't set to smooth
effect(target_handler);
render_effect(() => {
return () => {

Loading…
Cancel
Save