question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning: useLayoutEffect does nothing on the server, because its effect cannot […]

See original GitHub issue

Version 4 of <ButtonBase> now incorporates useLayoutEffect() in the src code here. This wasn’t present in version 3.

I understand the need for it however every jest test for a component that has a <Button> within it now results in console warnings like so:

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://fb.me/react-uselayouteffect-ssr for common fixes.
          in ForwardRef(ButtonBase)
          in WithStyles(ForwardRef(ButtonBase))
          in ForwardRef(Button)
          in WithStyles(ForwardRef(Button)) (at ButtonWithIcon/index.tsx:57)
          in Layout (at ButtonWithIcon/index.tsx:26)
          in ButtonWithIcon (at OAuthButton/index.tsx:58)
          in Layout (at OAuthButton/index.tsx:21)
          in OAuthButton (at OAuthSignUp.tsx:221)
          in div (at OAuthSignUp.tsx:200)
          in Layout (at OAuthSignUp.tsx:138)
          in OAuthSignUp (at OAuthSignUp.unit.test.tsx:60)
          in Context.Provider
          in ThemeProvider (at testProviders.tsx:29)
          in Context.Provider (at store.tsx:36)
          in Provider (at testProviders.tsx:28)
          in Providers (at OAuthSignUp.unit.test.tsx:59)

The tests still pass as it’s just a warning, but is there any way to prevent these warning messages from appearing? I literally can’t even see all the warnings in my terminal as there are so many.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:31
  • Comments:53 (38 by maintainers)

github_iconTop GitHub Comments

7reactions
oliviertassinaricommented, Jun 1, 2019

Ok found it. We can close this issue. You can reproduce the problem without Material-UI:

import React from "react";

const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;

function MadeWithLove() {
  useEnhancedEffect(() => {});

  return (
    <span>
      {"Built with love by the "}
    </span>
  );
}

The problem is that next-with-apollo traverse the tree, by default, on the browser with the server side API:

I have used Apollo extensively for more than a year at onepixel.com. I would be cautious with it, it can be slow at scale, it was our bottleneck n°1 from a performance perspective (graphql + apollo client). I believe you don’t need to traverse the React tree with the server side API on the client when switching routes. You can have loaders or a centralized getInitialProps logic instead.

5reactions
ndeviantcommented, Sep 5, 2019

@oliviertassinari yeah, totally. Thats would be great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix the "Warning: useLayoutEffect does nothing on the ...
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >
useLayoutEffect does nothing on the server · Issue #6 - GitHub
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >
useLayoutEffect and SSR - Medium
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >
useLayoutEffect and the warning on SSR - Eight Bites
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >
useIsomorphicLayoutEffect() react hook - usehooks-ts
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found