-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overlay causes useLayoutEffect
warnings in SSR mode
#1453
Comments
I agree with @jclem here because there is no obvious reason for why we need Here's what I tried,
Apart from an error that made me add When I removed the conditional from rendering logic for Overlay in my component, I saw this warning, So, I'm curious about how your bug and nextjs app looks like. Ideally I'd expect nothing from |
I'll have to go back a bit and find a commit this was still happening. Sorry for the delay, but I should be able to get to it in the next couple of days. |
Was able to reproduce this here Looking at ways to mitigate this! |
Linking to this exploration by @siddharthkp https://github.com/pksjce/nextjs-primer-react/pull/1/files |
Describe the bug
When using the
<Overlay />
and components that build upon it in SSR mode, React emits warnings about callinguseLayoutEffect
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 auseIsomorphicLayoutEffect
, which @mattcosta7 reminded me about in Slack:(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:
<Overlay />
on some pageThe text was updated successfully, but these errors were encountered: