New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FOUC with Webpacker 4.0.0.pre.pre.2 and webpack-dev-server with HMR: true #1542
Comments
I tried a ton of configurations to get hmr working, and nothing works. I am on 4.0.0.pre.pre.2, and I tried adding each of extract-text-webpack-plugin no longer works with Webpack 4. |
I've got the same thing, using typescript ( |
I'm also seeing the FOUC with webpacker 4.0.2 and Rails 5.2, when using the |
You probably want to set |
*something changes* (If you only changed a js file, start at 5.)
This issue has also been discussed a lot by non-webpackER folks, eg:
Once you start to understand the steps, you can connect the dots in a way that makes sense for your stack. Hope this helps. |
@gauravtiwari setting extract_css = true in development requires that you use <%= stylesheet_pack_tag %> in order to load css. In general, our team is experiencing this pain point: #1720 (comment). Which requires you add the right style sheets with stylesheet_pack_tag whenever a react component uses a stylesheet. Is there a better way to do this? |
@derrickmar To solve this problem, we set the style extractor to only extract styles from files following a naming convention, eg: Here is the regex for the MiniCssExtractPlugin loader: This is a webpacker/package/utils/get_style_rule.js Line 41 in 41d79c9
|
@jakeNiemiec that's an interesting idea but that doesn't solve FOUC because local styles are still imported via JS as you said. |
A: If you add the JS in your B: If you intend for your app to be rendered server-side, you would need to seek help in other SSR-related issues in this repo like #2085 or #2074. (I don't use SSR) |
I was able to prevent FOUC and enable HMR for stylesheets like this: In Webpacker const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// Replace default MiniCssExtractPlugin loader config to enable HMR
// You might want to change "sass" to the loader that you actually use
// Default loaders are `css`, `sass`, `moduleCss` or `moduleSass`
environment.loaders.get('sass').use[0] = {
loader: MiniCssExtractPlugin.loader,
options: {
hmr: true,
},
};
// Remove [hash] from filename in the plugin so HMR is able to match the file to refresh
environment.plugins.get('MiniCssExtract').options.filename = 'css/[name].css'; In development:
extract_css: true
# ...
dev_server:
hmr: true
inline: true
# ... Ensure you have |
Can this issue be closed ? |
I'm getting a flash of unstyled content whenever I reload a page in the most current version of Webpacker 4.x.
I'm mostly using the vanilla config; however, as far as I can tell this takes into account hmr being enabled and switches to
style-loader
frommini-css-extract-plugin
. It's worth mentioning that this is an upgrade from Webpacker v3.5 to 4; I did runrails webpacker:install
after the upgrade.Here's my config:
development.js
is vanilla. I'm aware I've a lot of dependencies I can remove frompackage.json
(mostly from playing around with an earlier version of Webpacker) but I assume they're not at fault here.Apologies if this isn't a ton of info to go on, and am happy to provide anything required. Kudos =)
Edit a day or so later:
I'm going to add a bit to this. When I set
hmr
andinline
to false and have webpack-dev-server running, I had expected to begin seeing the CSS without the flash of unstyled content at the beginning. Instead, I'm never seeing my compiled css and the page remains unstyled.I'd guess this is somehow due to a misconfiguration on my part with Webpacker; however, I'd have nonetheless expected the default configuration of Webpacker to be close enough to optimal to not require much tinkering on my part, so I'm mentioning this here. I am, of course, also curious what I'm doing wrong 😄
The text was updated successfully, but these errors were encountered: