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

implement gatsby-plugin-jss #1431

Merged

Conversation

vovacodes
Copy link
Contributor

this also adds a new lifecycle callback onClientRender to Browser API.
It is called when the initial render of a Gatsby App is done on the client.

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 8, 2017

Deploy preview ready!

Built with commit ac3d08f

https://deploy-preview-1431--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 8, 2017

Deploy preview failed.

Built with commit ac3d08f

https://app.netlify.com/sites/gatsbygram/deploys/59778bc9424ef2018a48eaab

@KyleAMathews
Copy link
Contributor

This looks awesome! Thanks!

Any reason not to use https://www.gatsbyjs.org/docs/browser-apis/#onClientEntry?

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 8, 2017

Deploy preview ready!

Built with commit ac3d08f

https://deploy-preview-1431--gatsbyjs.netlify.com

@vovacodes
Copy link
Contributor Author

@KyleAMathews, when onClientEntry is called the <style> tag generated by JSS on the client is not yet in the DOM, so if at this moment we remove the one generated on the server there will be no styles applied to the html until ReactDOM.render is executed and JSS inserted the "client-side" styles to the DOM. This may cause the page to flash from styled view to unstyled and back to styled again.

@vovacodes vovacodes force-pushed the topic/implement-gatsby-plugin-jss branch from 8d4fa84 to 5d5bf77 Compare July 9, 2017 08:27
@KyleAMathews
Copy link
Contributor

So from this discussion it looks like they've solved the SSR/client hydration issues for the next version of JSS https://github.com/cssinjs/react-jss/pull/107

I'd rather not add an special-case API to work around a bug in another library... could we just add JSS support with the client styles hydration not quite working knowing this will get fixed soon on the next release?

@KyleAMathews
Copy link
Contributor

@wizardzloy Ok with taking out the new API? Would love to get this in soon!

@KyleAMathews
Copy link
Contributor

Also could you add a very simple example site similar to the example sites for other css plugins.

@vovacodes
Copy link
Contributor Author

@kof could you please confirm that with react-jss v7.0.0 we don't need to remove the SSR-generated <style> tag after rendering on the client?

@KyleAMathews

Also could you add a very simple example site similar to the example sites for other css plugins.

Could you please provide a link to one of those for a reference?

@kof
Copy link

kof commented Jul 15, 2017

Removing critical css style tag is still required after application was mounted. Just added a note to the readme of react-jss. It was previously documented in the core only.

We never perceived this as a bug and had no plans to change it for now for basically 2 reasons:

  1. it is easy to remove a style node
  2. It gives you some freedom in how you would like to implement ssr styles and critical styles.

Also note that not removing it might have no negative consequences. It will though if resulting runtime css differs to the ssr and conflicts, leading to ssr overriding the client-side. This might happen though in some cases, so better remove it.

@KyleAMathews
Copy link
Contributor

@kof I don't understand why removing the SSR styles is necessary. Are styles generated differently during SSR? Why would it matter if they're there or not?

@kof
Copy link

kof commented Jul 15, 2017

@kof I don't understand why removing the SSR styles is necessary. Are styles generated differently during SSR? Why would it matter if they're there or not?

JSS has http://cssinjs.org/json-api?v=v8.1.0#function-values which is mutative. On the server, one specific state is used, on the client, state might change over time, but the same CSS rule is used which has the same selector, but a different property.

@KyleAMathews
Copy link
Contributor

But if the initial props used are the same on both server and client we're fine?

@kof
Copy link

kof commented Jul 15, 2017 via email

@vovacodes
Copy link
Contributor Author

@KyleAMathews I really like the idea of keeping the API surface as small as possible but doesn't onClientRender look quite logical to allow the plugins to hook to? We build Gatsby on top of React and this hook maps perfectly to the React's API do you see any particular issue with having it onboard?

@kof
Copy link

kof commented Jul 15, 2017

Mb it helps if you show more useful use cases. I understand the hesitation for adding a new hook function which needs to be maintained when there is only one particular use case which sounds like an optional. Mb its good to see a general usefulness using some examples.

@@ -1,17 +1,24 @@
{
"name": "gatsby-plugin-jss",
"version": "1.0.1",
"description": "Stub description for gatsby-plugin-jss",
"version": "2.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the version to 1.0.0

@KyleAMathews
Copy link
Contributor

yes, as long as props don't change at runtime, also not in the future.

Ok, so to be safe they'd definitely need removed.

This is a low-risk API to add and there's perhaps other use cases and I'd definitely like to support JSS. Let's change the name of the API though to onInitialClientRender as the current name makes it seem like it'll be called on every render.

@vovacodes vovacodes force-pushed the topic/implement-gatsby-plugin-jss branch from 5d5bf77 to 8fe5882 Compare July 22, 2017 08:08
this also adds a new lifecycle callback "onInitialClientRender" to Browser API.
It is called when the initial render of a Gatsby App is done on the client.
@vovacodes vovacodes force-pushed the topic/implement-gatsby-plugin-jss branch from 8fe5882 to 5831e38 Compare July 22, 2017 08:10
@vovacodes
Copy link
Contributor Author

@KyleAMathews Thanks for the review and feedback, I changed the name of the hook to onInitialClientRender, added using-jss website to the examples, updated the version of react-jss to the latest stable version - 7.0.2

@KyleAMathews KyleAMathews merged commit f01497b into gatsbyjs:master Jul 25, 2017
@KyleAMathews
Copy link
Contributor

Awesome! Really happy to have a JSS plugin added!

@KyleAMathews
Copy link
Contributor

Deploy preview failed.

Built with commit ac3d08f

https://app.netlify.com/sites/using-glamor/deploys/59778bca424ef2018a48eabd

@KyleAMathews
Copy link
Contributor

Deploy preview failed.

Built with commit ac3d08f

https://app.netlify.com/sites/using-contentful/deploys/59778bcb424ef2018a48eac3

@vovacodes vovacodes deleted the topic/implement-gatsby-plugin-jss branch July 25, 2017 19:24
This was referenced Mar 16, 2018
@jlengstorf
Copy link
Contributor

Hiya @wzrdzl! 👋

This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here.

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

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

Successfully merging this pull request may close these issues.

None yet

5 participants