Skip to content
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

Dev mode: useLayoutEffect warning is back #1410

Closed
nkuehn opened this issue Oct 28, 2022 · 7 comments
Closed

Dev mode: useLayoutEffect warning is back #1410

nkuehn opened this issue Oct 28, 2022 · 7 comments
Assignees
Labels
🚀 Status: Groomed All is known to start development 💅 Type: Enhancement Improves existing code

Comments

@nkuehn
Copy link
Collaborator

nkuehn commented Oct 28, 2022

Dev mode now throws the following warning:

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. 
This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. 
To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. 
See https://reactjs.org/link/uselayouteffect-ssr for common fixes.

The only place where we directly use it is still the sidebar, but there is a specific comment and handling for the case. Maybe we need to revisit the possible workarounds / fixes from the react docs and pick a different one, .

@nkuehn nkuehn added the 💅 Type: Enhancement Improves existing code label Oct 28, 2022
@gabriele-ct
Copy link
Contributor

Some findings:

  • the warning definitely doesn't come from the sidebar. I even tried to remove entirely the code and I still get the warning when the homepage loads. As additional confirmation, disabling the isomorphic hack in sidebar, I get a lot more of warnings.
  • The warning is certainly generated by some code in @commercetools-docs/gatsby-theme-docs package as even the most minimal implementation (websites/site-template) generates that warning and the only dependency it has is indeed @commercetools-docs/gatsby-theme-docs
  • My hypothesis is that it might be related to some dependency we use that is not ssr safe, but I can't figure out what is actually causing the error
  • Looking at the error stack trace I can guess it's something related with the MDXProvider (see below the stack trace)
at ThemeProvider (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:626:79)
    at LayoutApplication (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:55655:32)
    at LayoutContentHomepage (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:55446:78)
    at ErrorBoundary (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:53951:5)
    at ThemeProvider (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:54971:258)
    at IntlProvider (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:127796:47)
    at HomepageTemplate (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:56898:16)
    at RouteHandler (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:140597:5)
    at div
    at FocusHandlerImpl (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:59732:5)
    at FocusHandler (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:59703:19)
    at RouterImpl (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:59608:5)
    at Location (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:59437:23)
    at Router
    at ServerLocation (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:59545:19)
    at MDXProvider (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:28095:46)
    at MDXScopeProvider (/Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:53131:3)
    at /Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:53351:15
    at /Users/gabrieleantonini/projects/commercetools-docs-kit/websites/site-template/.cache/page-ssr/routes/render-page.js:28078:48

@gabriele-ct
Copy link
Contributor

Running grep -rnwl '.' -e 'useLayoutEffect in the node_modules directory returns several results of files containing useLayoutEffect but here is how far i can get. @nkuehn and @FFawzy any idea?

@emmenko
Copy link
Member

emmenko commented Nov 10, 2022

I think this is coming from uikit's ThemeProvider

https://github.com/commercetools/ui-kit/blob/0a42178c2c733cf31120fa208db182399887677e/design-system/src/theme-provider.tsx#L71

We'll think about making it more SSR compatible. cc @CarlosCortizasCT

@gabriele-ct
Copy link
Contributor

I think this is coming from uikit's ThemeProvider

you just need to ask to the right people 🤣

@emmenko
Copy link
Member

emmenko commented Nov 10, 2022

FYI: opened a tracking issue commercetools/ui-kit#2329

@nkuehn
Copy link
Collaborator Author

nkuehn commented Dec 23, 2022

Thank you @emmenko !

@nkuehn
Copy link
Collaborator Author

nkuehn commented Dec 23, 2022

I'll close this now because a root cause fix is out of scope for this repo and the practical issue is resolved for now.

@nkuehn nkuehn closed this as completed Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Status: Groomed All is known to start development 💅 Type: Enhancement Improves existing code
Projects
None yet
Development

No branches or pull requests

4 participants