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

Conversation

threepointone
Copy link
Contributor

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?

@@ -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 ' +
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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"

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

@gaearon gaearon left a 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

Copy link
Collaborator

@gaearon gaearon left a 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',
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',

@gaearon
Copy link
Collaborator

gaearon commented Feb 21, 2019

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.

@gaearon
Copy link
Collaborator

gaearon commented Feb 21, 2019

(You'll also need to provide a small runnable CodeSandbox example in your issue to better illustrate your problem.)

@dimensi dimensi mentioned this pull request Feb 22, 2019
@threepointone threepointone reopened this Jul 9, 2019
@necolas necolas added the React Core Team Opened by a member of the React Core Team label Jan 8, 2020
@threepointone
Copy link
Contributor Author

closing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants