From e880185e950f24cfb7e209b58b1ba814812a62bc Mon Sep 17 00:00:00 2001 From: Damian Pieczynski Date: Tue, 26 Sep 2023 16:47:13 +0200 Subject: [PATCH] fix: useWindowVirtualizer locking scrolling position (#592) --- packages/react-virtual/src/index.tsx | 1 + packages/solid-virtual/src/index.tsx | 2 ++ packages/svelte-virtual/src/index.ts | 1 + packages/virtual-core/src/index.ts | 2 +- packages/vue-virtual/src/index.ts | 2 ++ 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-virtual/src/index.tsx b/packages/react-virtual/src/index.tsx index 05bebb6f..29c6be8b 100644 --- a/packages/react-virtual/src/index.tsx +++ b/packages/react-virtual/src/index.tsx @@ -81,6 +81,7 @@ export function useWindowVirtualizer( observeElementRect: observeWindowRect, observeElementOffset: observeWindowOffset, scrollToFn: windowScroll, + initialOffset: typeof document !== 'undefined' ? window.scrollY : undefined, ...options, }) } diff --git a/packages/solid-virtual/src/index.tsx b/packages/solid-virtual/src/index.tsx index 8d5b1833..537519f3 100644 --- a/packages/solid-virtual/src/index.tsx +++ b/packages/solid-virtual/src/index.tsx @@ -122,6 +122,8 @@ export function createWindowVirtualizer( observeElementRect: observeWindowRect, observeElementOffset: observeWindowOffset, scrollToFn: windowScroll, + initialOffset: + typeof document !== 'undefined' ? window.scrollY : undefined, }, options, ), diff --git a/packages/svelte-virtual/src/index.ts b/packages/svelte-virtual/src/index.ts index 29169a4e..42621b7e 100644 --- a/packages/svelte-virtual/src/index.ts +++ b/packages/svelte-virtual/src/index.ts @@ -92,6 +92,7 @@ export function createWindowVirtualizer( observeElementRect: observeWindowRect, observeElementOffset: observeWindowOffset, scrollToFn: windowScroll, + initialOffset: typeof document !== 'undefined' ? window.scrollY : undefined, ...options, }) } diff --git a/packages/virtual-core/src/index.ts b/packages/virtual-core/src/index.ts index 9e69ad78..fb1d84aa 100644 --- a/packages/virtual-core/src/index.ts +++ b/packages/virtual-core/src/index.ts @@ -187,7 +187,7 @@ export const measureElement = ( export const windowScroll = ( offset: number, { - adjustments = window.scrollY, + adjustments = 0, behavior, }: { adjustments?: number; behavior?: ScrollBehavior }, instance: Virtualizer, diff --git a/packages/vue-virtual/src/index.ts b/packages/vue-virtual/src/index.ts index be7e7977..8cf49837 100644 --- a/packages/vue-virtual/src/index.ts +++ b/packages/vue-virtual/src/index.ts @@ -106,6 +106,8 @@ export function useWindowVirtualizer( observeElementRect: observeWindowRect, observeElementOffset: observeWindowOffset, scrollToFn: windowScroll, + initialOffset: + typeof document !== 'undefined' ? window.scrollY : undefined, ...unref(options), })), )