New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v5 createGlobalStyles does not work on production with 2 global styles #2670
Comments
|
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.... |
|
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 |
|
Not sure if related, but I want to leave it here as a note, as I workaround it: In my app, I sometimes need to rerender the whole app. With v3, v4 it worked without any problems. With v5, I had the issue, that the createGlobalStyles went missing after the rerender of the root element of the app in the style object. All other styles are ok. My workaround, I call: before the new render. I tried to reproduce it with the sandbox example app, but I couldn't, that's why I didn't create an issue. |
|
I observed this bug in storybook when select different stories and go back to previous story. V4 works fine. |
|
Looking into this a little more - The styles are properly output into the bundled scripts, and they're definitely being interpolated correctly. The styles are not applied. If I open up devtools (with react devtools installed), and click on the element in the component inspector, then I do see the styles applied. a quick check at debugging (don't have time to dig through deeply now). If I add a local state and use effect to force a re-render after initial mounting, the styles apply when that re-render occurs
|
|
I'm experiencing this one as well. Weird! |
|
I have this issue as well but with only one |
|
Just wanted to bump this. Not having the ability to use Global Styles with confidence is a large reason not to switch to v5. |
|
So there's one bug we're keeping an eye on re: rules with vendor prefixed-selectors. But I'm successfully using multiple cGS in my nextjs production app with v5. |
|
@shalanah this is very likely due to a subtle bug we're trying to track down re: vendor-prefixed selectors. You can use tooling like this to find and remove them for the time being: https://stylelint.io/user-guide/rules/selector-no-vendor-prefix |
|
cc @kitten |
|
createGlobalStyles doesn't work on server side (next.js v8) but works on client |
|
It’s something with your setup, I use it in 5 separate nextjs projects and
it works.
…On Wed, Sep 4, 2019 at 7:49 AM yuliia007naumenko ***@***.***> wrote:
createGlobalStyles doesn't work on server side (next.js v8) but works on
client
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2670?email_source=notifications&email_token=AAELFVW2ZXVE7H3G5EWVIRLQH6OGJA5CNFSM4H6PSE3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD53JUCQ#issuecomment-527866378>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAELFVW6LPXPJDREDACKW3LQH6OGJANCNFSM4H6PSE3A>
.
|
|
That’s interesting. I’m using it on a fresh Next.js 9 repo. Global styling with S-C 5 on a page to page basis is not reliable. Styling seems to unload, even if the component is included on all pages. S-C 4 does not have this issue. The SSR setup has not changed either. If you have more info, let me know. |
|
Did you follow the next-styled-components example in the nextjs repo?
…On Wed, Sep 4, 2019 at 10:00 AM Jon Wheeler ***@***.***> wrote:
That’s interesting. I’m using it on a fresh Next.js 9 repo. Global styling
with S-C 5 on a page to page basis is not reliable. Styling seems to
unload, even if the component is included on all pages. S-C 4 does not have
this issue. The SSR setup has not changed either. If you have more info,
let me know.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2670?email_source=notifications&email_token=AAELFVQ2ST5ICAGCROOQODTQH65QLA5CNFSM4H6PSE3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD53VHNA#issuecomment-527913908>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAELFVTQPNDG7XP6T5NWC33QH65QLANCNFSM4H6PSE3A>
.
|
|
Sure did. |
|
Interesting. Do you have multiple libs using s-c that are consumed in the same app? Two copies loading at once can cause some interesting collisions. |
|
That I can confirm. 2 libs. Our Design System runs on S-C. And some other packages we use. Seems like you’re onto something. |
|
Make sure the design system labels s-c as a peer dependency and they’re
both running on the same version. The betas use a nonstandard semver range
so it doesn’t dedupe properly unless it’s the same.
…On Wed, Sep 4, 2019 at 10:18 AM Jon Wheeler ***@***.***> wrote:
That I can confirm. 2 libs. Our Design System runs on S-C. And some other
packages we use. Seems like you’re onto something.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2670?email_source=notifications&email_token=AAELFVU3ZRVNVKXJYMAINKTQH67UNA5CNFSM4H6PSE3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD53XGBQ#issuecomment-527921926>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAELFVQMILKKY43SJ7A3HLTQH67UNANCNFSM4H6PSE3A>
.
|
|
I totally remember the peer dependency quark. However, interestingly I found the DS having S-C set as a dependency AND peer dependency. 😑 |
|
We have the same problem in a next.js project. I checked our dependencies and our package-lock.json and we are only using 1 version of styled-components |
|
@probablyup @kitten I was able to confirm within our app that a vendor prefixed selection rule was causing the GlobalStyle issue. Note, this issue only happened in the production build version. Removing this rule resolved: /* Gecko Browsers */
::-moz-selection {
background: #C9F6F8;
}I was looking at the SC v5 source code, it looks like a few changes were made in how the css is being parsed/generated in GlobalStyle, I haven't dug in yet. I also noticed that the GlobalStyle component has about 50% higher rendering duration times, after upgrading from v4 to v5 (just within our app/not tested extensively). |
|
This is an interested find @sbrichardson. I'm using both |
|
I'm not using any vendor prefixes in our global styles, but still have the issue that they are not loaded all the time. |
|
@jonkwheeler @fabb I'm thinking that the |
|
@Ako92 but you didn't fix it. You just stopped using it. 😄 |
|
@umitkucuk yes. thanks for you comment. I will edit my answer. but i didn't find any other solution to fix. |
:-)) |
|
Maybe the remaining bug on |
|
I wonder if it's possible this is related to a Next.js bug I filed which demonstrates re-hydration of the |
|
@jonkwheeler very interesting... could be. |
|
Ok I found out more. cGS seems to work properly, except in combination with the next.js We currently have in our The weird thing is that in the So why did that work at all in sc 4? My guess would be that sc 4 did not collect global styles at all, where as sc 5 does - am I on the right track? ❓ So I dug some further, and even when I move the When I move the But when I put it inside a So it seems sc's I'll do some more checks to see if we are really ready for upgrade to sc 5 now when I just move the global styles out of |
|
@probablyup I think it would be helpful to add these things 👆 as breaking changes to the v5 release notes, what do you think? Something along these lines:
Note that the part about style collection is just guesswork on my side, based on evidence of the behavior in v5. It would be interesting to hear if this is actually the case, or which other change caused the new behavior. |
|
I'll give the release candidate a shot, but I'm 99% positive none of my |
|
Yeah, ours is in the |
|
The position shouldn’t matter as long as it is being rendered during the
gIP collection phase. If the Head is being rendered after gIP that would
explain why the styles aren’t there.
…On Fri, Nov 1, 2019 at 8:00 AM Marek Suscak ***@***.***> wrote:
Yeah, ours is in the _app.js outside of NextHead and Helmet and we were
seeing this issue until we downgraded.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2670?email_source=notifications&email_token=AAELFVUIQGOYBKJSHSPDJKLQRQK55A5CNFSM4H6PSE3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC2XSNQ#issuecomment-548763958>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAELFVVFU256SHOVM3GMYXDQRQK55ANCNFSM4H6PSE3A>
.
|
|
I believe that this should be a blocker for the version 5 release. I am pasting below a complete react index.js which is not working as desired. The same code works perfectly well on the v4. The first image is the result of a developer build. Now, this is the result of a production build. I am starting with react and I could not understand any of the workarounds that could be used and I can not make createGlobalStyle works properly on version v5. Fun-fact, the colors are being applied, but not the fonts. So, this shows that some point the style was rendered by styled-components, and later removed. index.js index.css |
|
It will always be empty in production because we use the cssom injection
APIs that browsers don’t surface in dev tools for some reason
…On Sat, Nov 2, 2019 at 3:16 PM Jenser Almeida ***@***.***> wrote:
I believe that this should be a blocker for the version 5 release. I am
pasting below a complete react index.js which is not working as desired.
The first image is the result of a developer build.
[image: image]
<https://user-images.githubusercontent.com/660075/68075689-5a01bc00-fd68-11e9-8406-1ba0558ed78c.png>
Now, this is the result of a production build.
[image: image]
<https://user-images.githubusercontent.com/660075/68075720-bf55ad00-fd68-11e9-8173-5c1ee5589339.png>
I am starting with react and I could not understand any of the workarounds
that could be used and I can not make createGlobalStyle works properly on
version v5. Fun-fact, the colors are being applied, but not the fonts. So,
this shows that some point the style was rendered by styled-components, and
later removed.
index.js
import "./index.css";
import React from "react";
import ReactDOM from "react-dom";
import { ThemeProvider, createGlobalStyle, css } from "styled-components";
const GlobalStyle = createGlobalStyle`
${props => props.theme.fonts.titleFace}
${props => props.theme.fonts.bodyFace}
${props => props.theme.fonts.iconsFace}
body {
font-family: ${props => props.theme.fonts.body}, sans-serif;
}
button {
color: ${props => props.theme.colors.color};
background: ${props => props.theme.colors.background};
border-color: ${props => props.theme.colors.border};
font-family: ${props => props.theme.fonts.body}, sans-serif;
}
button:hover {
background: ${props => props.theme.colors.highlightedBackground};
color: ${props => props.theme.colors.highlightedColor};
border-color: ${props => props.theme.colors.highlightedBorder};
}
button:after {
font-family: ${props => props.theme.fonts.icons};
}
`;
const theme = {
colors: {
color: "#fafafa",
background: "#181753",
border: "#181753",
highlightedColor: "#dfdfdf",
highlightedBackground: "#181753",
highlightedBorder: "#181753"
},
fonts: {
title: "Muli",
titleFace: css`
@font-face {
font-family: "Montserrat";
font-style: normal;
font-weight: 400;
src: local("Montserrat Regular"), local("Montserrat-Regular"),
url(https://fonts.gstatic.com/s/montserrat/v13/JTUSjIg1_i6t8kCHKm459Wlhyw.woff2)
format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC,
U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122,
U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
`,
body: "Montserrat",
bodyFace: css`
@font-face {
font-family: "Montserrat";
font-style: normal;
font-weight: 400;
src: local("Montserrat Regular"), local("Montserrat-Regular"),
url(https://fonts.gstatic.com/s/montserrat/v13/JTUSjIg1_i6t8kCHKm459Wlhyw.woff2)
format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC,
U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122,
U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
`,
icons: "icomoon",
iconsFace: css`
@font-face {
font-family: "icomoon";
src: url("./fonts/IcoMoon-Free.ttf") format("truetype");
font-weight: normal;
font-style: normal;
}
`
}
};
function App() {
return (
<ThemeProvider theme={theme}>
<GlobalStyle theme={theme} />
<HomePage />
</ThemeProvider>
);
}
function HomePage() {
return <button>Continue</button>;
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
index.css
body {
font-size: 16px;
font-weight: bold;
overflow-x: hidden !important;
position: relative;
}
button {
color: #fff;
font-size: 20px;
font-weight: bold;
padding: 11px 60px 11px 50px;
border-radius: 80px;
position: relative;
cursor: pointer;
box-shadow: 0 10px 16px 0 rgba(0, 0, 0, 0.2),
0 6px 20px 0 rgba(0, 0, 0, 0.19);
border: 3px solid;
}
button:focus {
outline: none;
}
button:active {
outline: none;
}
button:hover {
cursor: pointer;
}
button:after {
content: "\ea3c";
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
position: absolute;
right: 10px;
top: 28%;
-webkit-font-smoothing: antialiased;
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2670?email_source=notifications&email_token=AAELFVXBWGB6I2VWAER3FL3QRXGZBA5CNFSM4H6PSE3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC5C6NQ#issuecomment-549072694>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAELFVRWAZLPRNJYK6GIOU3QRXGZBANCNFSM4H6PSE3A>
.
|
|
@probablyup, please hold on. This latest fonts issue was my fault. My current codebase, which has all the styling in index.css except for the dynamic properties, works with the rc1. Just for the sake of testing, I will revert to my previous version where all the styling was managed by styled-components global style, to see if my previous issue is fixed with the current rc.1 |
npmPackages:
My SC version is not V5, but I have a similar problem for that. export default createGlobalStyle`
${reset}
* {
@import url('https://fonts.googleapis.com/css?family=Roboto&display=swap');
font-family: 'Roboto', sans-serif !important;
box-sizing: border-box;
background-color: red;
}
body {
min-height: ${props => props.theme.minHeight};
padding-top: ${props => props.theme.headerPadding};
}
`; |
|
@5h5ong what happens if you change it to |
|
@jonkwheeler Do you mean inside of css file? If then, Yes. Styles works fine in css file. I separated styles in css and html to solve this problem. |
|
@5h5ong I was referring to the createGlobalStyle snippet you posted. Does changing |
|
@jonkwheeler Oh..! html * {
...
}Does that mean? Thanks for the advice but nothing has changed. |
|
Hmm alright. I was just curious if the css parser couldn't understand something. Thanks for trying. Maybe it's the |
This is possibly a bug with styled-components where global styles are not injected when @import is used. Reference: styled-components/styled-components#2670
|
The issue is still present in I can also confirm that the issue is caused by the This is my globalStyle: import { createGlobalStyle } from 'styled-components';
export const GlobalStyles = createGlobalStyle`
body {
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css');
@import url('https://rsms.me/inter/inter.css');
font-family: 'Inter', sans-serif;
*, *::before, *::after {
box-sizing: border-box;
}
}
`; |
|
We are experiencing a similar issue on |
|
@GiovanniFrigo On this note, I’m pretty sure another bug in this issue that’s being mentioned, vendored rules is not occurring anymore, since we’ve fixed it. I also saw @PhEEP yes, third party scripts can often mess with our style tags when they’re moving our unmount if the node, or even editing it 😱 All in all these issues in this thread all different and either in my list above or unrelated. So I’ll close and lock this issue, please create separate threads so we can track your problems and help you separately! |


Environment
System:
Binaries:
npmPackages:
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.)
Expected Behavior
Styles from both global styles will appear
Actual Behavior
Only styles from
GlobalFontStylingappear.The text was updated successfully, but these errors were encountered: