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

suggest useEffect when useLayoutEffect triggers in server rendering #14596

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/react-dom/src/server/ReactPartialRendererHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,12 @@ export function useLayoutEffect(
false,
'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.',
'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',
Copy link
Collaborator

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',

);
}

Expand Down