slate icon indicating copy to clipboard operation
slate copied to clipboard

Optional flag to force "useEffect" instead of "useLayoutEffect" to aid in serialization

Open wfischer42 opened this issue 2 years ago • 1 comments

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, {...}):

Screen Shot 2022-04-11 at 5 21 04 PM

Context https://github.com/udecode/plate/issues/1047#issuecomment-1095332503 Tagging @dylans

wfischer42 avatar Apr 11 '22 21:04 wfischer42

Got exactly this problem now. How did it work in previous versions?

naorye avatar Apr 11 '22 23:04 naorye