parcel
parcel copied to clipboard
HMR is not working for inlined css (`@import`ed from `style` tag)
🐛 bug report
HMR is not working for inlined CSS (@import
ed from style
tag).
💻 Code Sample
index.html
<!DOCTYPE html>
<html>
<head>
<style>@import './index.css';</style>
</head>
<body>
</body>
</html>
index.css
body {
background-color: beige;
}
🎛 CLI Command
parcel index.html
🤔 Expected Behavior
Stylesheet reloaded when @import
ed css is saved.
😯 Current Behavior
HMR is not triggered when @import
ed css is saved.
🌍 Your Environment
Software | Version(s) |
---|---|
Parcel | 2.7.0 |
Node | v18.5.0 |
npm | 8.12.1 |
Operating System | macOS 12.5.1 |
If someone wants to look into this, I would expect changedAssets
to include both the CSS and HTML file here: https://github.com/parcel-bundler/parcel/blob/cbc84b0c1d538b0ec15a3bf01f95da3ed623ebbb/packages/reporters/dev-server/src/HMRServer.js#L160
Then, in the runtime, this check should fail and result in a page reload because one of the assets is not a CSS or JS file. https://github.com/parcel-bundler/parcel/blob/cbc84b0c1d538b0ec15a3bf01f95da3ed623ebbb/packages/runtimes/hmr/src/loaders/hmr-runtime.js#L136-L142
Looking into why this isn't the case would go a long way to figuring out what's going on here!
I would like to take a look at this.
One thing I've noticed is when I use /path/to/monorepo/packages/core/parcel/src/bin.js src/index.html
to start my server, HMR doesn't work at all, tried updating the html file while the server was running.
And the same does work when using yarn parcel src/index.html
.
Am I missing something?
UPDATE: It does work with the js file.
Okay now after some deep dive, here's what I have found:
When adding @import "./index.css";
and saving the html file, as you suggested @devongovett, changedAssets
does contain both html and css. And as a matter of fact, HMR actually works in that case.
Here's when it doesn't work: updating the already @import
ed css file because changedAssets
now only contains the css file and not html, so hmrAcceptCheck
returns true.
HMR is not triggered when @imported css is saved.
@baoshan Can you confirm when you say this ^, which one of these do you mean:
- the css file is saved?
- or the html file with the
@import
directive is saved?
HMR is not triggered when
@imported
css is saved.
I think I expressed it clearly: saving the css file does not trigger an expected HMR
Just ran into this. Just to make sure it's clear:
<link rel="stylesheet" href="./styles.css"> // HMR works with this
<style>
@import "./styles.css"; // HMR does not work with this
</style>
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.