#HTML-only flicker on page load

9 messages · Page 1 of 1 (latest)

old bronze
echo grail
#

Same here, In my case I guess it's coming from combine both of server component and client component, and I have no idea to fix this problem. That's why I were here.

dusk barn
strong zodiac
#

This has happened to me ( sometimes ) and i thought it's something to do with tailwind

dusk barn
#

well, i exclusively use tailwind and it has never ever happened to me

exotic zodiac
#

I have also been seeing this a lot, but haven't been able to track it down. It is most noticeable for me on pages where I am using heroicons because there is a flash of huge icon before everything lays out correctly

quick reef
old bronze
#

I have found that styled components is causing this issue for me.

Old version:
https://lb-vercel-jwlq7pb8j-euw.vercel.app/lol-boosting/solo
Fixed version:
https://lb-vercel-9rdpgcqer-euw.vercel.app/lol-boosting/solo

Since nextjs prerenders pages serverside, the css styles have to be applied serverside aswell.

Adding the following code to _document.js in the pages folder fixes it:

import Document from 'next/document'
import { ServerStyleSheet } from 'styled-components'

export default class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const sheet = new ServerStyleSheet()
    const originalRenderPage = ctx.renderPage

    try {
      ctx.renderPage = () =>
        originalRenderPage({
          enhanceApp: (App) => (props) =>
            sheet.collectStyles(<App {...props} />),
        })

      const initialProps = await Document.getInitialProps(ctx)
      return {
        ...initialProps,
        styles: (
          <>
            {initialProps.styles}
            {sheet.getStyleElement()}
          </>
        ),
      }
    } finally {
      sheet.seal()
    }
  }
}
quick reef
#

I found out this is a bug with firefox and the first answer on this thread has solved it for me: https://stackoverflow.com/questions/21147149/flash-of-unstyled-content-fouc-in-firefox-only-is-ff-slow-renderer. Hopefully this helps someone. Seems very hacky tbh but I couldn't resolve this any other way and have spent too much time on it at this point.