tim-soft / react-starter-kit-antd

React-Starter-Kit with Ant-Design Integration
MIT License
28 stars 4 forks source link

Flash of unstyled content (FOUC) #2

Open joenot443 opened 6 years ago

joenot443 commented 6 years ago

Thanks again @tim-soft for the very helpful repository.

I'm experiencing a FOUC when cloning the repo directly and building normally. Once the client has loaded, the page looks fine, however from what I can tell the antd styles are not being sent in the SSR HTML, meaning the resulting markup looks like this:

screen shot 2018-05-29 at 10 22 31 am

Perhaps I'm misunderstanding what's possible with antd / SSR, but if possible I'd like to be able to send the antd CSS in my SSR copy, to prevent the flash of unstyled content.

terry-ice commented 6 years ago

` { test: reStyle, rules: [ { test: /.css$/, include: [/node_modules\/.*antd/], loader: 'style-loader' },

      // Convert CSS into JS module
      {
        issuer: { not: [reStyle] },
        exclude: [/node_modules\/.*antd/],
        use: 'isomorphic-style-loader'
      },

      // Process external/third-party styles
      {
        exclude: path.resolve(__dirname, '../src'),
        loader: 'css-loader',
        options: {
          sourceMap: isDebug,
          minimize: !isDebug,
          discardComments: { removeAll: true }
        }
      },

      // Process internal/project styles (from src folder)
      {
        include: path.resolve(__dirname, '../src'),
        loader: 'css-loader',
        options: {
          // CSS Loader https://github.com/webpack/css-loader
          importLoaders: 1,
          sourceMap: isDebug,
          // CSS Modules https://github.com/css-modules/css-modules
          modules: true,
          localIdentName: isDebug
            ? '[name]-[local]-[hash:base64:5]'
            : '[hash:base64:5]',
          // CSS Nano http://cssnano.co/options/
          minimize: !isDebug,
          discardComments: { removeAll: true }
        }
      },

      // Apply PostCSS plugins including autoprefixer
      {
        loader: 'postcss-loader',
        options: {
          config: {
            path: './tools/postcss.config.js'
          }
        }
      }

      // Compile Less to CSS
      // https://github.com/webpack-contrib/less-loader
      // Install dependencies before uncommenting: yarn add --dev less-loader less
      // {
      //   test: /\.less$/,
      //   loader: 'less-loader',
      // },

      // Compile Sass to CSS
      // https://github.com/webpack-contrib/sass-loader
      // Install dependencies before uncommenting: yarn add --dev sass-loader node-sass
      // {
      //   test: /\.scss$/,
      //   loader: 'sass-loader',
      // },
    ]
  },`
terry-ice commented 6 years ago

clientConfig.module.rules[0].options.plugins = [ ...clientConfig.module.rules[0].options.plugins, ['import', { libraryName: 'antd', style: 'css' }] ]

terry-ice commented 6 years ago

I encountered this problem and solved it@joenot443

terry-ice commented 6 years ago

@joenot443 you can see my config https://github.com/terry-ice/react-starter-kit-antd/blob/master/tools/webpack.config.js

joenot443 commented 6 years ago

@terry-ice thanks so much for making that repository to help me out. Unfortunately, I'm still finding the ant styles are not sent along with SSR, and so I still get the FOUC. Note, as soon as the ant styles loads, it looks fine. However there is still a brief flash where the page looks like this:

screen shot 2018-05-29 at 10 52 20 am

joenot443 commented 6 years ago

Note that that screenshot is while using the exact repository you linked.

terry-ice commented 6 years ago

I will try to configure tomorrow to see if I can solve it,good night. @joenot443

talentedandrew commented 6 years ago

@joenot443 were you able to solve the FOUC issue?

joenot443 commented 6 years ago

@talentedandrew I wasn't unfortunately.