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.

createGlobalStyle is reproducing wrong styling in production mode

See original GitHub issue

Environment

Node v10x

Reproduction

Its a react app, and I pass some styles including css reset and body, html basic styles using createGlobalStyle which works perfectly fine when working locally. However, I noticed the same styles are being ignored or didn’t get imported when application is built using webpack production mode.

See results below. Tried many different tests, but it seems to be behaving indifferently which maybe caused by bug within css string to style tag compilation.

Steps to reproduce

Build script using webpack production mode.

Expected Behavior

screenshot 2018-11-13 at 5 40 06 pm

Actual Behavior

screenshot 2018-11-13 at 5 41 19 pm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
shobhitsharmacommented, Nov 28, 2018

@probablyup Nice! It has been great experience working with this library. Love to contribute next time!

1reaction
imbhargav5commented, Nov 14, 2018

Can you try something like this and let us know? The thing is, in your example. The CGS runs on every render, which means the same styles are injected each time they are created which leaks memory. Can you try this eg and let me know?

       const GlobalCSSReset = createGlobalStyle`
            ${ResetCSS}
        `;
        const GlobalFonts = createGlobalStyle`
            ${(fontFamilies as any)[mode]}
        `;
        const GlobalDefaults = createGlobalStyle`
            *,
            *:before,
            *:after {
                box-sizing: border-box;
            }

            html, body {
                font-family: ${(props: any) => props.theme.global.fontFamily}, sans-serif;
                color: ${(props: any) => props.theme.colors.primary};
                -webkit-font-smoothing: antialiased;
                -moz-osx-font-smoothing: grayscale;
                overflow-x: hidden;
                text-rendering: optimizeLegibility;
            }

            a {
                color: ${(props: any) => props.theme.colors.primary};
            }

            b, strong, h1, h2, h3, h4, h5 {
                font-family: ${(props: any) => props.theme.global.fontFamily600}, sans-serif;
            }
        `;

class GlobalStyle extends React.Component<{ ... }, { ... }> {
    public render(): JSX.Element {
        const { mode } = this.props;
       
        return (
            <React.Fragment>
                <GlobalFonts mode={mode} />
                <GlobalCSSReset   />
                <GlobalDefaults />
            </React.Fragment>
        );
    }
}

export default GlobalStyle;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styled Component v5.3 createGlobalStyles not Working
Is the error message not enough? It is saying that GlobalStyle doesn't render children. See styled-components.com/docs/api#createglobalstyle ...
Read more >
Build a React theme switcher app with styled-components
In this tutorial, we demonstrate how to build a custom theme switcher for a Game of Thrones-themed React app using styled-components.
Read more >
styled components not working in prod nextjs - You.com
js projects using MUI + styled-components based on the example configuration from:\ have incorrect MUI components styling on production. The order of the...
Read more >
Reactjs PopUp: Easily Create Popups in React - CopyCat Blog
import { createGlobalStyle } from 'styled-components'. function App() { ... Common Issues While Building Reactjs PopUp in production.
Read more >
Theming styled-components with CSS custom properties
They are supported on 94.75% of the browser market share, so it's even production-ready. Defining a custom property is like setting a CSS ......
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