Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace typeof window checks with typeof document #516

Merged
merged 1 commit into from
Feb 26, 2023
Merged

fix: replace typeof window checks with typeof document #516

merged 1 commit into from
Feb 26, 2023

Conversation

redabacha
Copy link
Contributor

@redabacha redabacha commented Feb 26, 2023

currently the @tanstack/react-virtual package throws useLayoutEffect does nothing on the server warnings during ssr when using a deno runtime. this is because deno has a global window object available for browser compatibility (though is being considered for removal denoland/deno#13367). also see here for further reading.

this pr replaces all typeof window checks across all packages with typeof document instead which works in all environments.

prior art: motiondivision/motion#1522

@vercel
Copy link

vercel bot commented Feb 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
react-virtual ❌ Failed (Inspect) Feb 26, 2023 at 2:55AM (UTC)

@@ -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!),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would have always evaluated to null since it should have been lowercase window instead of Window 😅

@piecyk piecyk merged commit bc16c19 into TanStack:beta Feb 26, 2023
@piecyk
Copy link
Collaborator

piecyk commented Feb 26, 2023

Thanks @redabacha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants