mobxjs / mobx-react

React bindings for MobX

Home Page:https://mobx.js.org/react-integration.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document `enableStaticRendering`

cmdcolin opened this issue · comments

We currently perform SSR and have the SSR'd component wrapped in an observer. It produces a warning message about useLayoutEffect being used on the server side

This a crazy little codebox that might demonstrate what we're seeing

https://codesandbox.io/s/hidden-sun-2wnte?file=/src/App.js

The console warnings are

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.
    in _c
    in _c (at App.js:34)

This came from updating mobx-react/mobx-react-lite from and getting the useQueuedForceUpdate new-ness, which looked good, but seems like it triggers this warning

Had mobx-react-lite@2.0.7 now on mobx-react-lite@2.2.2

Thanks, that definitely makes sense. I'll close for now

ps: I know this is just crazy but we actually do what is done in the codesandbox e.g. ssr on the client side (sometimes in a web worker, sometimes in the main thread, but we may have to stop the main thread ssr'ing)

I'd swear I wrote docs on it, but missed something else already as well. I guess I messed up a docs merge somewhere

Added to the main docs as well