Skip to content

Instantly share code, notes, and snippets.

@unyo
Created January 29, 2019 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unyo/29df22ec751c00e98056b0074f456aa4 to your computer and use it in GitHub Desktop.
Save unyo/29df22ec751c00e98056b0074f456aa4 to your computer and use it in GitHub Desktop.
Remove gatsby FOUC (flash of unstyled content / text)
// apparently there is some hidden settings at https://www.gatsbyjs.org/docs/debugging-replace-renderer-api/#fixing-the-replacerenderer-error
import React from "react"
import { renderToString } from "react-dom/server"
import { ServerStyleSheet, StyleSheetManager } from "styled-components"
export const replaceRenderer = ({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents,
}) => {
const sheet = new ServerStyleSheet()
const app = () => (
<StyleSheetManager sheet={sheet.instance}>
{bodyComponent}
</StyleSheetManager>
)
replaceBodyHTMLString(renderToString(<app />))
setHeadComponents([sheet.getStyleElement()])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment