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.

styled components HOCs do not work in production builds

See original GitHub issue

Bug report

Describe the bug

I have an HOC that uses styled components to generate a button. The HOC works in development mode. Given two different CSS inputs, it produces two different components:

Screen Shot 2020-02-17 at 2 17 08 PM

However, in production builds, only one component is produced:

Screen Shot 2020-02-17 at 2 17 55 PM

I’ve pared this down to a very small example that anyone can clone an run. Here is the code listing:

https://github.com/dminkovsky/next-styled-broken-prod/blob/master/pages/index.js

To Reproduce

  1. Clone https://github.com/dminkovsky/next-styled-broken-prod
  2. yarn run dev and go to localhost:3000, observe dev result.
  3. yarn run build && yarn run start and go to localhost:3000, observe prod result.

Expected behavior

Prod and dev should be the same.

Screenshots

Please see above.

System information

  • OS: macOS 10.14.6
  • Browser (if applies): N/A, same in all browsers.
  • Version of Next.js: 9.2.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dminkovskycommented, Feb 18, 2020

It occurred to me to attempt to reproduce this directly from with-styled-components. Turns out that using a direct fork of canary, on which styled components is at version 4, this problem does not exist.

However, when I upgraded the example to version five, the problem appeared: https://github.com/dminkovsky/next.js/commit/6f9dd40025fe8024a2b8854f90810c7fc975b2db. I will review the latest docs for server rendering and see if something different has to be done in _document.js.

Update

Reviewed the styled components SSR docs. Not seeing anything different for v5. I opened an issue in styled-components: https://github.com/styled-components/styled-components/issues/3026.

0reactions
balazsorban44commented, Jan 27, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Styled Components stripped out from production build
In development everything works fine (first screenshot), but when I run a production build ( npm build ), styles within style tags are...
Read more >
Releases - styled-components
Updating styled components is usually as simple as npm install . Only major versions have the potential to introduce breaking changes (noted in...
Read more >
Advanced (LEGACY) - MUI System
The makeStyles (hook generator) and withStyles (HOC) APIs allow the creation of multiple style rules per style sheet. Each style rule has its...
Read more >
JSS integration with React
Lazy evaluation - Style Sheets are created when a component mounts and removed when it's unmounted. The static part of a Style Sheet...
Read more >
React v18.0 – React Blog
Many of the features in React 18 are built on top of our new concurrent ... Server Components is not inherently coupled to...
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