styled-components: v5 createGlobalStyles does not work on production with 2 global styles
Environment
System:
- OS: macOS 10.14.5
- CPU: (12) x64 Intel® Core™ i7-8850H CPU @ 2.60GHz
- Memory: 489.05 MB / 16.00 GB
- Shell: 3.2.57 - /bin/bash
Binaries:
- Node: 10.15.1
- Yarn: 1.16.0
- npm: 6.9.0
npmPackages:
- styled-components: ^5.0.0-beta.8 => 5.0.0-beta.8
Reproduction
I have 2 global styles, however on production only the second one loads. (The class names appear fo the first, but no styles are applied.)
import { createGlobalStyle } from 'styled-components/macro';
const GlobalStyling = createGlobalStyle`
html {
height: 100%;
}
:global(#root) {
min-height: 100%;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
flex: 1;
}
body {
min-height: 100%;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
flex: 1;
max-width: 100vw;
}
button {
cursor: pointer;
}
main, section {
display: block;
}
hr {
margin: 48px 0;
border-bottom: 1px solid gray;
border-top: none;
border-left: none;
border-right: none;
}
*:focus {
outline: 1px solid blue;
}
}`
const GlobalFontStyling = createGlobalStyle`...`;
ReactDOM.render(
<div>
<GlobalStyling />
<GlobalFontStyling />
<ErrorBoundary>...
</ErrorBoundary
</div>,
document.getElementById('root')
);
Expected Behavior
Styles from both global styles will appear
Actual Behavior
Only styles from GlobalFontStyling appear.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 58 (12 by maintainers)
I have this issue as well but with only one
createGlobalStyles. Even odder, Firefox seemed to apply the styles fine but Safari and Chrome would not.Just wanted to bump this. Not having the ability to use Global Styles with confidence is a large reason not to switch to v5.
This is an interested find @sbrichardson.
I’m using both
::-moz-selectionand::selectionin my global style injection. I 100% think you’re onto something. 🐴I’m experiencing this one as well. Weird!
I’ve actually come across the same issue today, but with only a single createGlobalStyle element. Will try to investigate later on today if I can
To fix
createGlobalStyle, you removed it? That is a “work around” some could use. But that is the same as saying, my car is broke, and to fix it I road the bus to work today. (Kidding of course) 🤠@probablyup
I am also having this issue too. I am using only one
createGlobalStylebut it doesn’t affect on production mode.CRA: 3.1.1 styled-components: 5.0.0-beta.9
Looks like it may be a red herring – I tried combining styles and global styles into a single block.
Things like html/body/hr don’t load. That is, until I click the element for the global style in the react dom inspector. Then they suddenly load. Investigating still…