Open YellowSaleTag opened 8 months ago
Please create a github repo with the reproducible example of the problem, thank you
Thank you so much for taking the time to respond. I created a minimal example here.
I found the root cause.
It breaks when:
new MiniCssExtractPlugin({
chunkFilename: '[name].[contenthash].id-[id].css',
filename: '[name].[contenthash].css'
}),
It works when:
new MiniCssExtractPlugin({
chunkFilename: '[name].[contenthash].id-[id].css',
filename: '[name].css'
})
It seems [contenthash] with hot module reloading does not work. I use content hash to avoid caching of the CSS file.
Is there another way I can avoid caching of the css file?
I updated the minimal PoC to reflect this. Here too.
Attached is a screenshot of the PoC with [contenthash] and a stale CSS payload in hot reload network request.
Weird, I can't reproduce, even more, we have test cases for this...
Can you provide full steps using your repo above - https://github.com/YellowSaleTag/hmr-stale-css-payload/?
Hmm interesting, sure see the following.
main.css
request and payload. confirm the html
rule has padding
of 200px
padding
value in ./app/components/App/app.css to 50 px
hot update
network request - main.css
update request should have a payload with an html
padding
value of 50px
89
and 128
. At these lines change [name].css
to [name].[contenthash].css
.npm run build
npm run start
50px
), 6 (update to 200px
).main.[contenthash].css
you'll find padding: 50px
even though you changed it to 200px
how did you resolve this problem? I found this problem in my project too
See these comments / config
Use
'[name].css'
as contenthash appears to break...
[name].[contenthash].css
Have you tried generating your own unique hash?
https://webpack.js.org/plugins/mini-css-extract-plugin/#filename-option-as-function
See these comments / config
- https://github.com/YellowSaleTag/hmr-stale-css-payload/blob/45c80aff00cc4c37c0b7bae593ad24d373b6cded/webpack.config.js#L84
- https://github.com/YellowSaleTag/hmr-stale-css-payload/blob/45c80aff00cc4c37c0b7bae593ad24d373b6cded/webpack.config.js#L123
Use
'[name].css'
as contenthash appears to break...
[name].[contenthash].css
thanks,It's useful for my project
Bug report
CSS with [contenthash] not refreshing with HMR, webpack-dev-middleware
1. We see our stylesheet loaded in the document with the expected CSS.
2. We make an update to our CSS. We change the
padding
from50
to75
px.3. We see a request in the network tab for the CSS update. However, the contents is stale. It has the old value of
50
px.4. We refresh the page using the refresh button and see the updated value of
75
px.Package Versions
Webpack Config (relevant parts)
Middleware Config
Actual Behavior
padding
from50
to75
px.50
px.75
px.Expected Behavior
How Do We Reproduce?
Minimal configuration provided above for now...
Please paste the results of
npx webpack-cli info
here, and mention other relevant information