-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[example] Support Gatsby v2 #12331
Conversation
examples/gatsby/gatsby-ssr.js
Outdated
@@ -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 }) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
I did this, too. But I had to change another line in the withRoot() function in withRoot.js: Old content of the line:
This is what I changed there:
The problem was that the page context was not null but an empty object After the change, everything was rendering just fine with Gatsby V2. |
@mattes3 It's good to know. |
This is my temporary solution gatsbyjs/gatsby#6127 (comment) Note that I am using my Layout component above the page component. |
2f6c47b
to
45b1272
Compare
I have updated the source code so we support both Gatsby v1 and v2. |
* fix gatsby-ssr.js * let's merge
Closes #12320