Skip to content

Commit

Permalink
fix unstyled flash
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane98c committed Feb 11, 2021
1 parent f1facc8 commit 44ce8c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ServerStyleSheet } from "styled-components";
export default class MyDocument extends Document {
static getInitialProps({ renderPage }) {
const sheet = new ServerStyleSheet();
const page = renderPage(App => props =>
const page = renderPage((App) => (props) =>
sheet.collectStyles(<App {...props} />)
);
const styleTags = sheet.getStyleElement();
Expand All @@ -15,6 +15,17 @@ export default class MyDocument extends Document {
return (
<html>
<Head>
{
<style
dangerouslySetInnerHTML={{
__html: `
body #__next div {visibility: hidden}
body.loaded #__next div {visibility: visible}
`,
}}
></style>
}
<title>Shane Loeffler</title>
{this.props.styleTags}
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
3 changes: 3 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as React from "react";
import Layout from "../components/Layout";
import Highlight from "../components/Highlight";

if (process.browser) {
document.body.classList.add("loaded");
}
const projects = [
{
img: "../static/img/maptheblacksnake.png",
Expand Down

1 comment on commit 44ce8c6

@vercel
Copy link

@vercel vercel bot commented on 44ce8c6 Feb 11, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.