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

useWindowScroll is SSR incompatible #1764

Closed
ivan-kleshnin opened this issue Jul 11, 2022 · 5 comments
Closed

useWindowScroll is SSR incompatible #1764

ivan-kleshnin opened this issue Jul 11, 2022 · 5 comments
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@ivan-kleshnin
Copy link

What package has an issue

@mantine/hooks

Describe the bug

https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-window-scroll/use-window-scroll.ts#L10
relies on direct window checks, should be hidden behind useEffect.

In which browser did the problem occur

Any

If possible, please include a link to a codesandbox with the reproduced problem

No response

Do you know how to fix the issue

No response

Are you willing to participate in fixing this issue and create a pull request with the fix

No response

Possible fix

Related thread on SO: https://stackoverflow.com/questions/57230099/react-ssr-proper-way-of-handling-page-scroll-position

@brunocrosier
Copy link
Contributor

do you have a repro for this?

@brunocrosier
Copy link
Contributor

from what i can see, this hook works as intended on the client and server:

https://codesandbox.io/s/brave-yonath-4rxbje?file=/pages/index.js

@ivan-kleshnin
Copy link
Author

ivan-kleshnin commented Jul 27, 2022

As I remember it "works" but triggers well known "hydration mismatch" warning. SSR compatible code must not have if (window...) like conditions. I don't have a repo around, sorry. I've switched to Chakra and removed related Mantine playgrounds 😅

@brunocrosier
Copy link
Contributor

As I remember it "works" but triggers well known "hydration mismatch" warning. SSR compatible code must not have if (window...) like conditions. I don't have a repo around, sorry. I've switched to Chakra and removed related Mantine playgrounds 😅

where do you see the hydration mismatch exactly ? unfortunately i can't see this error it in the codesandbox demo (i looked in the server and client console). if i can see the error, i will investigate and fix it.

@rtivital rtivital added Fixed patch Completed issues that will be published with next patch (1.0.X) and removed bug labels Aug 11, 2022
@rtivital
Copy link
Member

Fixed in 5.1.4, for this and other similar hooks – initial value is not set in useEffect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

3 participants