Skip to content

Commit

Permalink
fix: replace typeof window checks with typeof document (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
redabacha authored Feb 26, 2023
1 parent 9712ef5 commit bc16c19
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/react-virtual/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export * from '@tanstack/virtual-core'
//

const useIsomorphicLayoutEffect =
typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect
typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect

function useVirtualizerBase<
TScrollElement extends Element | Window,
Expand Down Expand Up @@ -77,7 +77,7 @@ export function useWindowVirtualizer<TItemElement extends Element>(
>,
): Virtualizer<Window, TItemElement> {
return useVirtualizerBase<Window, TItemElement>({
getScrollElement: () => (typeof window !== 'undefined' ? window : null!),
getScrollElement: () => (typeof document !== 'undefined' ? window : null!),
observeElementRect: observeWindowRect,
observeElementOffset: observeWindowOffset,
scrollToFn: windowScroll,
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-virtual/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function createWindowVirtualizer<TItemElement extends Element>(
mergeProps(
{
getScrollElement: () =>
typeof window !== 'undefined' ? window : null!,
typeof document !== 'undefined' ? window : null!,
observeElementRect: observeWindowRect,
observeElementOffset: observeWindowOffset,
scrollToFn: windowScroll,
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-virtual/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function createWindowVirtualizer<TItemElement extends Element>(
>,
): Readable<SvelteVirtualizer<Window, TItemElement>> {
return createVirtualizerBase<Window, TItemElement>({
getScrollElement: () => (typeof window !== 'undefined' ? window : null!),
getScrollElement: () => (typeof document !== 'undefined' ? window : null!),
observeElementRect: observeWindowRect,
observeElementOffset: observeWindowOffset,
scrollToFn: windowScroll,
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-virtual/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export function useWindowVirtualizer<TItemElement extends Element>(
return useVirtualizerBase<Window, TItemElement>(
computed(() => ({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
getScrollElement: () => (typeof Window !== 'undefined' ? window : null!),
getScrollElement: () =>
typeof document !== 'undefined' ? window : null!,
observeElementRect: observeWindowRect,
observeElementOffset: observeWindowOffset,
scrollToFn: windowScroll,
Expand Down

0 comments on commit bc16c19

Please sign in to comment.