Repository navigation
Fix undefined sheet error when SSR without rendering any styles - #391
kristojorg wants to merge 2 commits into
Conversation
|
Hey @kristojorg, this is great, thanks for taking the time to submit a PR! We just rebuilt the entire SSR system in #214, which was merged into the Thanks so much again! |
|
Cool, I just submitted a new PR to the v2 branch with a fix :-) ! Hope it helps |
|
How to install the v2 branch? I tried I've tried using https://github.com/styled-components/babel-plugin-styled-components but my app crashed after installing it. Any heads up? |
|
|
|
Thanks for your reply. Before using this I will wait until v2 is stable, because literally none of my styles work after updating (although the babel plugin error did disappear haha). |
|
Oh oops 🙈 are you server-side rendering? |
|
Not yet. Is that required with v2? Still need to use the flush etc, or is the |
|
Not required with v2 at all, |
|
Ok thanks, will try the example shown in 214. Yes indeed, no serverside rendering atm. For instance my import React, { Component } from 'react';
import { Link } from 'react-router';
import styled from 'styled-components';
class Header extends Component {
render() {
return (
<HeaderElem>
<NavElem>
<NavLink to="/">
<span>Terug</span>
</NavLink>
<NavTitle>Title of my page</NavTitle>
</NavElem>
</HeaderElem>
);
}
}
const HeaderElem = styled.header`
position: fixed;
top: 0;
left: 0;
`;
const NavElem = styled.nav`
display: flex;
position: relative;
width: 100vw;
padding: 21px 20px 16px;
color: #fff;
font-size: 18px;
text-align: center;
background: #38659e;
`;
const NavLink = styled(Link)`
position: absolute;
left: 20px;
top: 50%;
transform: translate(0, -50%);
color: #fff;
text-decoration: none;
`;
const NavTitle = styled.div`
flex-grow: 2;
`;
export default Header;So for now I downgraded to 1.3.1 again ;) |
|
Did you build the v2 branch after
then
After that it worked fine |
|
Ohh that's my mistake when I published that then @kristojorg! 🙈 will fix that with the next pre-release! |
|
Thanks for pointing that out, although building doesn't seem to fix my problem. <style type="text/css">.sc-bdVaJa {}.sc-bwzfXH {}.sc-htpNat {}.sc-bxivhb {}.sc-ifAKCX {}.sc-EHOje {}.sc-bZQynM {}.sc-gzVnrw {}.sc-htoDjs {}.sc-dnqmqq {}@font-face {
font-family: 'Aller';
font-weight: 500;
@font-face {
font-family: 'Aller';
font-weight: 200;
@font-face {
font-family: 'Aller';
font-weight: 800;
html {
text-rendering: optimizeLegibility;
box-sizing: border-box;
}
*,
*:after,
*:before {
box-sizing: inherit;
margin: 0;
padding: 0;
}
.sc-iwsKbI {}.leMwTI {
position: relative;
width: 100%;
min-height: 100vh;
background-image: url('/achtergrond.png?f196c');
background-size: cover;
}
.sc-gZMcBi {}.dOVyUJ {
position: fixed;
top: 0;
left: 0;
}
.sc-gqjmRU {}.sc-VigVT {}.sc-jTzLTM {}.sc-fjdhpX {}.haSjo {
position: absolute;
top: 124px;
left: 50%;
width: 330px;
-webkit-transform: translate(-50.4%, 0);
-ms-transform: translate(-50.4%, 0);
transform: translate(-50.4%, 0);
}
.sc-jzJRlG {}.gyjQZj {
list-style: none;
}
.sc-cSHVUG {}.cjEito {
border-bottom: 2px solid #fff;
background: #38659e;
}
.cjEito:last-of-type {
border-bottom: 0;
}
.sc-chPdSV {}.ieEmoF {
position: absolute;
bottom: 54px;
left: 0;
width: 100%;
}
.sc-kgoBCf {}.sc-kGXeez {}.gVQFWk {
position: absolute;
bottom: 0;
width: 175px;
height: 170px;
text-align: center;
text-decoration: none;
background: no-repeat bottom center/40%;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
left: 100px;
}
.gVQFWk:active {
background-position: center 70px;
}
@-webkit-keyframes kuBrLH {
from {
left: -1000px
}
to {
left: -470px
}
}</style>So somehow I thought moving the styled elements would work. And this worked. The styles where added, but my global styles (body styling and font-face) didn't load. I prettified my code above, but it looks like it isn't loading the in correct order. Also they're many empty classes which seems not like it use to be. I downgraded to 1.3.1 again and moved most of my styles back outside the component. I hope styles outside the component will still be allowed in v2 since it looks a lot clearer to me! |
When SSR without any styles, StyleSheet.sheet returned by glamor is
undefined, and thus the cssRules property is undefined. I have
substituted this with an empty array instead, and it is now working in
my case. This should solve one of the issues mentioned multiple times in
#124.
Side note: this is my first ever PR anywhere... please let me know if I'm doing something dumb