Warning in tests/MainThreadRpcDriver: useLayoutEffect does nothing on the server
See original GitHub issueThis warning shows up in tests on master branch (see e.g. here) and anytime that MainThreadRpcDriver is used:
Warning: 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. See https://fb.me/react-uselayouteffect-ssr for common fixes.
It looks like this is related to Material-UI, and the warning appears when server-side rendering is done in an environment where a DOM is detected (like when everything is done in the main thread, which we do in out tests). Further reference: https://github.com/mui-org/material-ui/issues/15798
Issue Analytics
- State:
- Created 3 years ago
- Comments:20 (4 by maintainers)
Top Results From Across the Web
How to fix the "Warning: useLayoutEffect does nothing on ...
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >useLayoutEffect does nothing on the server · Issue #1373 · ...
I'm getting the following warning whereas I'm not using "useLayoutEffect" hook anywhere in my code. react-dom-server.browser.development.js:104 ...
Read more >useLayoutEffect and SSR
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >useLayoutEffect and the warning on SSR - Eight Bites
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >What is useLayoutEffect Hook & how it compares to useEffect?
"Warning: useLayoutEffect does nothing on the server because its effect cannot be encoded into the server renderer's output format...".
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
but you are saying it could be triggered by other portions of the codebase as well…
if you comment out this section in config/jest/console.js
then you will get a ton of useLayoutEffect warnings when running tests
this will match also what is seen when using MainThreadRpc in the app since tests use MainThreadRpc
The only reason we don’t get those warnings in the tests right now is because of that code snippet which silences them
Note that the memory leak by using mainthreadrpc may not be really something that is good to ignore
We render large numbers of observer components when using SvgFeatureRendering for example (every single subfeatures is an observer)
Using #1727 does not fix this issue. Only something like #1733 can conceptually fix that e.g. skipping SSR on the main thread entirely