question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Styles not rendered on the server

See original GitHub issue

I’ve noticed styles are not rendered on the server and are only rendered once the client app starts, causing a brief flash of unstyled content. When I looked at build/assets.json, the css key was missing after running yarn start, but is present after running yarn build. If it’s intentional to extract the styles only for a production build, I’m trying to understand how the styles can be rendered prior to the client app starting and preventing the FOUC.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
jaredpalmercommented, Jul 5, 2017

This only happens during development. There is no FOUC when run in production. If this is problematic, I suggest extending razzle to use extract text webpack plugin to pull out style sheets during dev just as they are pulled in razzle-build. I am not sure that HMR will work the way you expect if you make this change

0reactions
Himadu2000commented, Dec 5, 2022

For anybody else, ran into a similar problem that scss is not loading. Replacing the style-loader with MiniCssExtractPlugin fixed it.

modifyWebpackConfig({
  env: { target, dev },
  webpackConfig,
  options: { webpackOptions },
}) {
  const config = webpackConfig

  if (target === "web" && dev) {
    // Replacing style-loader with MiniCssExtractPlugin
    const rules = [...config.module.rules]
    const { cssOutputFilename, cssOutputChunkFilename } = webpackOptions

    const { use } = rules.find(({ test }) =>
      test?.source?.includes(".(sa|sc)ss$")
    )

    const index = use.findIndex(({ loader }) =>
      loader.includes("style-loader")
    )

    if (index > -1) use[index] = MiniCssExtractPlugin.loader

    config.plugins.push(
      new MiniCssExtractPlugin({
        filename: cssOutputFilename,
        chunkFilename: cssOutputChunkFilename,
      })
    )
  }

  return config
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my .css file not fully rendering on server, but working ...
Essentially, my style.css file is only partially rendering on the live server, despite working properly in my local development environment.
Read more >
CSS styles and images not rendered by server in DEV/PROD ...
Hi, i'v got issue with styles and images not rendered on server side in nextjs typescript app, on client everything works fine.
Read more >
How To Render CSS on React App Servers | DigitalOcean
Unfortunately, styled-components are not rendered to the server which makes them unavailable at that time.
Read more >
Server rendering - Material UI - MUI
The key step in server-side rendering is to render the initial HTML of the component before we send it to the client-side. To...
Read more >
Styling - Remix
When the route is no longer active, the stylesheet is removed. ... render" in order to extract the styles from the component tree...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found