styled components HOCs do not work in production builds
See original GitHub issueBug 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:
However, in production builds, only one component is produced:
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
- Clone https://github.com/dminkovsky/next-styled-broken-prod
yarn run devand go to localhost:3000, observe dev result.yarn run build && yarn run startand 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:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.
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.