-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
suggest useEffect when useLayoutEffect triggers in server rendering #14596
suggest useEffect when useLayoutEffect triggers in server rendering #14596
Conversation
@@ -281,7 +281,9 @@ export function useLayoutEffect( | |||
"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 ' + |
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.
I think grammar gets a bit clunky. It's almost a run-on sentence.
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.
Maybe I shouldn't add anything else, except for the link to the site?
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.
"This will lead to a mismatch between the initial, non-hydrated UI, and the intended UI. If possible, replace useLayoutEffect with useEffect which doesn't block the first paint. However, if this effect must run before the user sees anything, you can change this component to only render on the client. To learn more, see https://fb.me/react-warning-server-uselayouteffect"
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.
damn, thanks for that. love it.
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.
done
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.
Marking as in need of wording change + doc
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.
Looks good. Want to merge after the link works?
"doesn't block the first paint. However, if this effect must run " + | ||
'before the user sees anything, you can change this component to only ' + | ||
'render on the client. To learn more, see ' + | ||
'https://fb.me/react-warning-server-uselayouteffect', |
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.
this reads as very jargony to me… my suggestion:
'useLayoutEffect is not supported during server rendering. This call ' +
'is a no-op, but it likely indicates a bug because the effect will ' +
'not run until your component is hydrated on the client. If this ' +
'effect can be safely run after the component appears, replace ' +
'useLayoutEffect with useEffect. If not, you can change this ' +
'component to only render on the client. See ' +
'https://fb.me/react-warning-server-uselayouteffect',
Please ask a question in an issue, not a PR. When PR gets merged or closed, the discussion is hard to find — even if an issue is still active. |
(You'll also need to provide a small runnable CodeSandbox example in your issue to better illustrate your problem.) |
closing this |
Working on a separate PR for reactjs.org that this error will point to, started this PR to get approval on the copy. Works for everyone?