7

I'm using NextJs for my app and I'm having a FOUC on production. I'm not using styled components, just moduled and global CSS/SCSS. I assume the problem may be from my _document.js file

import React from 'react';
import Document, {Html, Head, Main, NextScript} from 'next/document';

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
    return {...initialProps};
  }

  render() {
    return (
      <Html>
        <Head>
          <link href="/static/scss/vendor/antd.css" rel="stylesheet" />
          <link href="/static/scss/vendor/bootstrap.min.css" rel="stylesheet" />
          <link href="/static/scss/base/typography.css" rel="stylesheet" />
          <link href="/static/scss/base/ionicons.min.css" rel="stylesheet" />
          <link href="/static/scss/base/flaticons.css" rel="stylesheet" />
          <link href="/static/scss/base/reset.css" rel="stylesheet" />
        </Head>
        <body>
          <div id="fb-root" />
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;
  • it might be your document.js in nextjs documentation the getinitialprops is a bit different than your code: https://nextjs.org/docs/advanced-features/custom-document one other problem might be not turning off ssr for components you want to load fully on client. it can be done with `import dynamic from 'next/dynamic'; export const Home = dynamic(() => import('./home'), { ssr: false, });` – Evaa Dec 11 '22 at 08:54

0 Answers0