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

[example] Support Gatsby v2 #12331

Merged
merged 2 commits into from
Aug 21, 2018
Merged

Conversation

blukai
Copy link
Contributor

@blukai blukai commented Jul 29, 2018

Closes #12320

@@ -5,7 +5,7 @@ import { renderToString } from 'react-dom/server';
import { JssProvider } from 'react-jss';
import getPageContext from './src/getPageContext';

exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString, setHeadComponents }) => {
export const replaceRenderer = ({ bodyComponent, replaceBodyHTMLString, setHeadComponents }) => {
Copy link
Member

Choose a reason for hiding this comment

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

This is not what I see in the docs: https://www.gatsbyjs.org/docs/ssr-apis/. Is this for v2?

Copy link
Contributor Author

@blukai blukai Jul 29, 2018

Choose a reason for hiding this comment

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

yup, I could not get ssr to work properly for few hours, then with some random console logs I've noticed that it doesn't work at all so I tried to export it as const and it worked.

here's repo with some stuff so u can test: https://github.com/blukai/puuffin, try to change export const replaceRenderer to exports.replaceRenderer and build it (yarn build && http-server public), then go to /contact page and u'll notice (hit F5), that some styles are broken, while with export const replaceRenderer everything looks ok.

if everything is ok, should I disable eslint rule for this line?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

We are waiting on gatsby to release a stable version to document it: #12320. I'm putting this PR on hold. Thanks for starting it!

Copy link

Choose a reason for hiding this comment

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

How did you get the console logs? When I write console.log() inside gatsby-ssr.js, it does not appear on the screen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattes3 yeah, it doesn't work in gatsby-ssr.js, I was writing console logs in getPageContext.js and withRoot.js

@oliviertassinari oliviertassinari added the on hold There is a blocker, we need to wait label Jul 29, 2018
@oliviertassinari oliviertassinari changed the title fix gatsby-ssr.js [example] Upgrade gatsby to v2 Jul 29, 2018
@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Jul 29, 2018
@mattes3
Copy link

mattes3 commented Aug 1, 2018

I did this, too. But I had to change another line in the withRoot() function in withRoot.js:

Old content of the line:

this.pageContext = this.props.pageContext || getPageContext();

This is what I changed there:

this.pageContext = Object.assign(this.props.pageContext ? this.props.pageContext : {}, getPageContext());

The problem was that the page context was not null but an empty object {}. That way, a new page context including the MuiTheme was NEVER created! Material-UI had no chance to use the correct theme and JSS.

After the change, everything was rendering just fine with Gatsby V2.

@oliviertassinari
Copy link
Member

@mattes3 It's good to know.

@HriBB
Copy link

HriBB commented Aug 3, 2018

This is my temporary solution gatsbyjs/gatsby#6127 (comment)

Note that I am using my Layout component above the page component.

@oliviertassinari oliviertassinari removed the on hold There is a blocker, we need to wait label Aug 21, 2018
@oliviertassinari oliviertassinari self-assigned this Aug 21, 2018
@oliviertassinari oliviertassinari changed the title [example] Upgrade gatsby to v2 [example] Support Gatsby v2 Aug 21, 2018
@oliviertassinari oliviertassinari merged commit 9bd1e8e into mui:master Aug 21, 2018
@oliviertassinari
Copy link
Member

I have updated the source code so we support both Gatsby v1 and v2.
@blukai It's a great first pull request on Material-UI 👌🏻. Thank you for giving it a shot!

marcelpanse pushed a commit to marcelpanse/material-ui that referenced this pull request Oct 2, 2018
* fix gatsby-ssr.js

* let's merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants