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.

Not all styled components working in development

See original GitHub issue

Bug 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: grafik

Development: grafik

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dietrichmaxcommented, Oct 28, 2020

upgraded to next@10.0.0 and the issue is gone.

1reaction
jamesmosiercommented, Oct 26, 2020

Closing for now. If anyone has a reproduction feel free to post it 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQs - styled-components
Commonly asked questions about styled-components.
Read more >
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 >

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