slate
slate copied to clipboard
Optional flag to force "useEffect" instead of "useLayoutEffect" to aid in serialization
Problem
Despite the useIsomorphicLayoutEffect
function, the serializeHtml
plugin leads to a console full of useLayoutEffect does nothing on the server...
warnings because it calls ReactDOMServer.renderToStaticMarkup(Slate, {...})
from the client to generate serialized code. Slate's CAN_USE_DOM
passes the check, but ReactDOMServer supplies the useLayoutEffect
function, which produces the warning.
This isn't a problem with Slate, but the easiest solution would be in Slate
Solution
While it's not necessarily Slate's problem, the simplest solution would be an optional Slate component flag that forces useIsomorphicLayoutEffect
to point to useEffect
, instead of exclusively relying on the typeof window...
checks. Something like useSSR
or noLayoutEffects
or something?
Alternatives
I'm not sure if this is possible... Could Slate inspect the location that React's resolveDispatcher().useLayoutEffect
refers to, and include that in the useIsomorphicLayoutEffect
check? Here's what it looks like in the console when Slate calls useLayoutEffect
from ReactDOMServer.renderToStaticMarkup(Slate, {...})
:

Context https://github.com/udecode/plate/issues/1047#issuecomment-1095332503 Tagging @dylans
Got exactly this problem now. How did it work in previous versions?