Open johannesaxner-valtech opened 4 years ago
We've got same problem(
@johannesaxner-valtech Did you solve it somehow?
No, we've just stayed with styled-components 4.
Looks like this is a 5.2 issue, introduced from this change:
downgrading to 5.1.x should resolve this.
Looks like that __SERVER__
boolean variable is set at compile time to create a browser and non-browser dist bundle?. This is sort of related to https://github.com/reactjs/React.NET/issues/1232. Because of this, the useLayoutEffect lines are the one that gets bundled (https://github.com/styled-components/styled-components/blob/f12b943658a9731ab6af6548a780019f696a09cb/packages/styled-components/src/constructors/createGlobalStyle.js#L60-L63).
@dustinsoftware would you have any ideas about the above? I'm thinking perhaps a separate webpack config for server and browser, where server webpack config would have targets: "node"
set, but when I tried that the JSEngine isn't able to resolve the modules (complaining about 'export' and 'import' syntax from memory).
I'm happy to create an issue in styled-components repo about this, though I do not understand fully the context of why they have changed this check from typeof window !== "undefined"
to __SERVER__
in this commit (https://github.com/styled-components/styled-components/commit/f12b943658a9731ab6af6548a780019f696a09cb)
@mattywong did you find a way to solve this issue. Have the same issue.
Just got this project to work on and not sure if sticking to 5.1.1 breaks any-other potion of the site. And __SERVER__
is hard-coded in rollup.config.js.
Thanks
In short, everything works fine with styled-components version 4.x, but when we tried upgrading to version 5.x, global styles would not be injected for server-side rendering, only component styles. The symptom is flash of unstyled content until react has loaded and started, in our very visible due to us reseting margins etc in our styled-components global styles.
I'm a front-end developer so not sure about all environment details but the only thing changed between working and not working is bumping the version of styled-components from 4.4.1 to 5.2.0.