Skip to content

Geist UI don't work on first reload for nextjs website in production #455

Answered by Deep-Codes
borngraced asked this question in Q&A
Discussion options

You must be logged in to vote

Adding this to pages/_document.tsx should solve the Cumulative Layout Shift Problem.

import Document, { Html, Head, Main, NextScript, DocumentContext } from 'next/document'
import CssBaseline from '@/styles/css-baseline';

class MyDocument extends Document {
  static async getInitialProps(ctx: DocumentContext) {
    const initialProps = await Document.getInitialProps(ctx)
    const styles = CssBaseline.flush()

    return {
      ...initialProps,
      styles: (
        <>
          {initialProps.styles}
          {styles}
        </>
      ),
    }
  }

  render() {
    return (
      <Html>
        <Head />
         <body>
               <Main />
               <NextScript />
          </

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@karlosos
Comment options

Answer selected by ofekashery
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants