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: hide useLayoutEffect warning when using SSR #10

Merged
merged 3 commits into from
Nov 28, 2021

Conversation

adi-li
Copy link
Contributor

@adi-li adi-li commented Nov 27, 2021

When using SSR and invoked useLayoutEffect inside the component, a warning
is prompted.

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.

I followed the hack proposed by @alexandereardon to resolve the issue.

When using SSR and invoked `useLayoutEffect` inside the component, a warning is prompted.

```
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.
```

Please see the [hack](https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a) proposed by @alexandereardon.
@VGLoic
Copy link
Owner

VGLoic commented Nov 28, 2021

Hey @adi-li ! Thanks a ton for this PR!

Do you mind if you change (I can also do it) the title of your PR to fix: hide useLayoutEffect warning when using SSR? In that way an auto release will be done containing this modification :)

@adi-li
Copy link
Contributor Author

adi-li commented Nov 28, 2021

Sure, let me change it.

@adi-li adi-li changed the title Hide useLayoutEffect warning when using SSR fix: hide useLayoutEffect warning when using SSR Nov 28, 2021
@VGLoic VGLoic merged commit 9ce45cd into VGLoic:main Nov 28, 2021
@github-actions
Copy link

🎉 This PR is included in version 2.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@adi-li adi-li deleted the feat/fix-nextjs-warning branch November 29, 2021 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants