Description
Describe the bug
When using the <Overlay />
and components that build upon it in SSR mode, React emits warnings about calling useLayoutEffect
during SSR.
Of course, there are legitimate uses of useLayoutEffect
in Primer and cases where it may be unavoidable. However, in <Overlay />
, it looks like this particular call is not doing any DOM measurement or direct manipulation, but is kicking off an animation. This seems like it's probably fine to defer until after a paint occurs, and I'm guessing that browser is probably going to do that anyway before this animation begins.
Given that, I wonder if we can move this to a useEffect
call, instead or alternatively investigate using a useIsomorphicLayoutEffect
, which @mattcosta7 reminded me about in Slack:
const useIsomorphicLayoutEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect
(That said, in this case, I think just using the simpler useEffect
is fine.)
In order to avoid these warnings currently, I have to defer completely the rendering of overlays until we're on the client.
To Reproduce
Steps to reproduce the behavior:
- Create a Next.js app
- Render an
<Overlay />
on some page - Watch logs