Skip to content
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

Styled components #28

Open
PEM-- opened this issue Feb 15, 2017 · 6 comments
Open

Styled components #28

PEM-- opened this issue Feb 15, 2017 · 6 comments

Comments

@PEM--
Copy link
Member

PEM-- commented Feb 15, 2017

Styled components allows specific behavior depending on its rendering origin:

  • On the server styles can be injected in the payload and the remaining CSS styles can be created a regular CSS file.
  • On the client, styles can be directly used within the React's components.

Using styled-components, we can avoid the FOUC (Flash Of Unknown Css) that plagues SPA and delay styles loading so that the HTML payload renders even faster its TTFB (Time To First Byte) with the real and appropriate styled tags.

@PEM-- PEM-- added this to the 4.0.0 milestone Feb 15, 2017
@Morganjackson
Copy link

Do you think this could be part of version 3.0?

I got this working with styled-components v2.0.0-7 by installing ssrwpo locally and addingcss = styleSheet.getCSS() but it would be nice to have this out of the box as its a showstopper for anyone using styled-components.

See https://github.com/diegohaz/arc/blob/fullstack/src/server.js#L77 for an example of SSR working with styled-components 1.4.4.

@PEM--
Copy link
Member Author

PEM-- commented Mar 15, 2017

Indeed, this out to be in our 3.0!

@PEM--
Copy link
Member Author

PEM-- commented Mar 15, 2017

Hey! @Morganjackson are you interested to do this? For this project, I don't want it to be a "one man knows it all". It's out to be a community based effort.

@Morganjackson
Copy link

@PEM-- I'm happy to contribute anyway I can, however I'm sure there is a better way to handle this than what I have hacked together.

import { styleSheet } from 'styled-components';
  if (!stepResults.hasUnwantedQueryParameters) {
    bodyMarkup = renderToString(app);
    css = styleSheet.getCSS()
    helmetHead = rewind();
  }
  if (stepResults.body === null) {
    stepResults.head = `<style type="text/css">${css}</style>`
    stepResults.body = `<div id="react">${bodyMarkup}</div>${stepResults.contextMarkup}`;
  }

This works but I think it should be in if (stepResults.head === null) but I'm not sure how.

@PEM--
Copy link
Member Author

PEM-- commented Mar 15, 2017

@Morganjackson I've just invited you on our Slack account. It would be easier to start this new journey. @mxstbr's work is assuredly part of it 😉

@PEM-- PEM-- modified the milestones: 3.0.0, 4.0.0 Apr 3, 2017
@PEM-- PEM-- self-assigned this Apr 3, 2017
@PEM-- PEM-- removed this from TODO in v4 - Apollo & Above the fold Apr 3, 2017
@cbilotta
Copy link
Member

This is done.

Now we just need to keep up with the styled-components potential API changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants