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.

Browser leaves duplicated style node when using ssr

See original GitHub issue

Current behavior:

Hydrate will not de-dup

截屏2021-09-10 下午5 26 53

To reproduce:

Create a styled component and put into page:

const App = () => (
  <Button />
  <Button />
  <Button />
  <Button />
  <Button />
);

Expected behavior:

It’s OK to get duplicated style definition on Server render: 截屏2021-09-10 下午5 28 43

But it should de-dup when hydrate on client side.

Environment information:

  • react version: 17.0.2
  • @emotion/react version: 11.4.1

I think it may same as #2436

https://github.com/emotion-js/emotion/blob/676a92631ef9c35cfd9f8660cce58aa0f7781528/packages/cache/src/index.js#L263

I guess hydrate logic do not dedup which makes too many same style keep in the page.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
max-ch9icommented, Dec 6, 2021

Wrapping in CacheProvider has helped in my case:

const myCache = createCache({ key: "cache-key" });

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <CacheProvider value={myCache}>
      <Component {...pageProps} />
    </CacheProvider>
  );
}
0reactions
haukurmarcommented, Jul 8, 2022

We had this problem with @emotion/react v11.9.0 but it seems to fixed in v11.9.3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why We're Breaking Up with CSS-in-JS
The ability to use JavaScript constants in styles reduces duplication in some cases, since the same constant does not have to be defined...
Read more >
Duplicate style render on SSR
I'm currently developing CMS with Gatsby and emotion. Style is ... Here's rendered result on browser(CSS Style is literally duplicated).
Read more >
Server-Side Rendering
Even though the demo illustrates the basic idea of SSR, it still leaves open questions: How to deal with styles? Node doesn't understand...
Read more >
Keeping Server-Side Rendering Cool With React Hydration
The purpose of this article is to share some helpful things to keep in mind to render a seamless experience as a Server-Side...
Read more >
Rendering on the Web
Where should we implement logic and rendering in our applications? Should we use Server Side Rendering? What about Rehydration?
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