-
Notifications
You must be signed in to change notification settings - Fork 137
fix: add useIsomorphicLayoutEffect to fix SSR warnings
#2503
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
base: main
Are you sure you want to change the base?
fix: add useIsomorphicLayoutEffect to fix SSR warnings
#2503
Conversation
|
🎭 Component Tests Report is ready. |
| export const useIsomorphicLayoutEffect = | ||
| typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export const useIsomorphicLayoutEffect = | |
| typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect; | |
| export const useLayoutEffect = typeof window === 'undefined' ? () => {} : React.useLayoutEffect; |
Using the name useLayoutEffect allows to lint the hook's dependencies. There is also no need to call useEffect as it has no effect on the server.
| const prevRootClassName = React.useRef(''); | ||
|
|
||
| React.useLayoutEffect(() => { | ||
| useIsomorphicLayoutEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other places where useLayoutEffect is used.
useIsomorphicLayoutEffect to fix SSR warningsuseIsomorphicLayoutEffect to fix SSR warnings
|
|
||
| import * as React from 'react'; | ||
|
|
||
| import {useLayoutEffect} from 'src/hooks/private'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import {useLayoutEffect} from 'src/hooks/private'; | |
| import {useLayoutEffect} from '../../hooks/private'; |
path should be relative
We use server side rendering and
useLayoutEffectspam into our logs with message: