suggest useEffect when useLayoutEffect triggers in server rendering#14596
suggest useEffect when useLayoutEffect triggers in server rendering#14596threepointone wants to merge 4 commits intofacebook:masterfrom
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.
I think grammar gets a bit clunky. It's almost a run-on sentence.
There was a problem hiding this comment.
Maybe I shouldn't add anything else, except for the link to the site?
There was a problem hiding this comment.
"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.
damn, thanks for that. love it.
gaearon
left a comment
There was a problem hiding this comment.
Marking as in need of wording change + doc
gaearon
left a comment
There was a problem hiding this comment.
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.
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?