Feliz icon indicating copy to clipboard operation
Feliz copied to clipboard

Question: useEffect instead of useLayoutEffect in useCallbackRef? (aka improve server side rendering compat)

Open gaku-sei opened this issue 4 years ago • 2 comments

Hello @Zaid-Ajaj 😄

It seems the useCallbackRef hook uses useLayoutEffect under the hood:

https://github.com/Zaid-Ajaj/Feliz/blob/4ec506747ca6baf155fed1d8c45d930e817887df/Feliz/React.fs#L393

But this leads to some issues with (Node.js based) server side rendering (you can see here for more details: https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85).

As per this comment:

https://github.com/Zaid-Ajaj/Feliz/blob/4ec506747ca6baf155fed1d8c45d930e817887df/Feliz/React.fs#L394

it seems the hook could be safely replaced by useEffect?

gaku-sei avatar Nov 03 '20 23:11 gaku-sei

Hi there @gaku-sei,

To be honest, I haven't played with Feliz yet in the context of server-side rendering but I believe we can replace useLayoutEffect by just useEffect. @Shmew Any concern about this?

Zaid-Ajaj avatar Nov 15 '20 01:11 Zaid-Ajaj

Using useEffect over useLayoutEffect causes issues, I explicitly remember testing the two out. I can't remember what exactly the issue was that occurs when you swap them out though; I wish the FSSF slack had more history in times like these 😩.

It might be possible to emulate useLayoutEffect via just useEffect by doing some raf shenanigans.

Shmew avatar Nov 15 '20 09:11 Shmew