next.js: React attempted to reuse markup in a container but the checksum was invalid

When I use styled-component feature extend with next.js

Version

next.js: 3.0.0-beta13 styled-component: 2.0.1

Steps to reproduce

I have UL component

const UL = styled.ul`
  padding: 0;
  margin: 0;
  list-style-type: none;
  outline: none;
`;

ListNave component

const ListNav = UL.extend`
  position: absolute;
  right: 0;
  display: flex;
  align-items: center;
  height: 100%;
`;

usage:

<ListNav>
    <li>a</li>
    <li>b</li>
    <li>c</li>
</ListNav>

Expected Behavior

No warning

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
 (client) g></a><ul class="sc-bdVaJa fPaAHZ" data-
 (server) g></a><ul class="sc-gqjmRU daXqbi" data-

Actual Behavior

There is a warning in console

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
 (client) g></a><ul class="sc-bdVaJa fPaAHZ" data-
 (server) g></a><ul class="sc-gqjmRU daXqbi" data-

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

What’s the best way to view and compare the server-rendered and client-rendered html? I have this same issue, but I’m not sure what’s causing it. I’d like to understand how to debug/diagnose. Thanks!

Having this issue at the moment. I’m not using extend, simply using bootstrap and using global styles as in this example: https://github.com/zeit/next.js/tree/master/examples/with-global-stylesheet

After removing bootstrap I stopped having the issue, so I investigated to see if it was something to do with Bootstrap, I found out that it doesn’t matter what CSS (or scss in my case) I’m using, it’s about the size. If I copy and paste the same rule for 3 o 4 thousand lines it will start giving me this error.

The error doesn’t happen all the time, and it seems it’s a problem with the sync of the server and the client? Not sure.

Anyone having a similar issue? Idk if I should open a new issue since this is unrelated to extend or styled components.

@timneutkens im having that issue even though im not using styled.extend or any of the things discussed on that issue 😢

Is there a solution to this? Getting a weird behaviour where my styles are flashing as they are being overridden.

sc-inspect