Not all styled components working in development
See original GitHub issueBug report
Describe the bug
After i run next
not all styled components are working in development mode. Everything was fine like a week ago but suddenly some components are not passing any css anymore. In production everything works as expected.
To Reproduce
I followed the example with-styled-components, so my _document.js
, _app.js
and .babel.rc
are looking like the following
_document.js
import Document from 'next/document';
import { ServerStyleSheet } from 'styled-components';
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;
try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App => props => sheet.collectStyles(<App {...props} />)
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
)
};
} finally {
sheet.seal();
}
}
}
_app.js
import Router from "next/router";
import React, { useEffect } from "react";
import App from "next/app";
import { init } from '@socialgouv/matomo-next';
import GlobalStyle from '@/styles/global.js'
//import CookieBanner from '@/components/cookies/cookie-banner' not used due to no cookies
import "prismjs/themes/prism-tomorrow.css";
import 'lazysizes';
const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL;
const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID;
class MyApp extends App {
componentDidMount() {
if (window.location.href.includes("mxd.codes")) {
init({ url: MATOMO_URL, siteId: MATOMO_SITE_ID });
}
}
render() {
const { Component, pageProps } = this.props;
return (
<>
<GlobalStyle/>
<Component {...pageProps} />
</>
)
}
}
export default MyApp;
.babelrc
{
"presets": ["next/babel"],
"plugins": [
["styled-components", { "ssr": true }]
]
}
Expected behavior
Css properties should be passed to components.
Screenshots
Production:
Development:
System information
- OS: [Windows]
- Version of Next.js: [e.g. 9.5.5]
- Version of Node.js: [e.g. 12.19.0]
Additional context
Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Styled-components is not working with react - Stack Overflow
I install styled components in my react project. but when I am styling using styled-components styling does not work.
Read more >Styled Components does not work on gatsby build ... - GitHub
Hello. I use gatsby-plugin-styled-components. Everything works perfectly when 'gatsby develop' is used. But once I use 'gatsby build' and ...
Read more >Next.js and Styled-Components: style loading issue
Have you tried using Styled-Components with your Next.js app but can't get the styles to load properly? This is because the server-side ...
Read more >Style your React Components like a Boss with ... - Codementor
styled -components exposes a React Context that works wonderfully with every component you build. You can create a theme object and use it ......
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 FreeTop 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
Top GitHub Comments
upgraded to next@10.0.0 and the issue is gone.
Closing for now. If anyone has a reproduction feel free to post it 🚀