-
-
Notifications
You must be signed in to change notification settings - Fork 427
changing imported css will be ignored in chunk hash #1660
Comments
After some more investigation it's not a "unnecessary" reload it's actually: Reload -> correct current version for a split second -> replaced by old cached version |
Making a "hard" reload will always work, but that just ignores "caching environments" which are the crucial part of this issue, as far as I can tell. The main problem is most likely this: chunk.code = … As this is done in a rollup bundle hook and not build hook the chunks hash will always remain the same even if you change complete contents of imported css files or any other part regarding css imports. This is pretty bad tbh. That means that caching prod environments won't apply css changes unless you also manually change at least anything in the contents of the chunks source. |
Alright there is this In my current case with the all imported css related contents and hashes already available: import { createHash } from 'crypto'
return {
name: 'my-css-plugin',
augmentChunkHash (chunk) {
let hash
for (const moduleId in chunk.modules) {
const css = cssCache[moduleId]
if (css) {
if (!hash) {
hash = createHash('sha256')
}
hash.update(css.hash)
}
}
if (hash) {
return hash.digest('hex')
}
},
… |
@dionysiusmarquis thanks for digging into this. I probably won't have time to work on this, but if you'd like to send a PR I'd be happy to review and merge |
I created a PR. I also tried to add support for additional "css extensions" like |
I just tried to reproduce this against |
@dionysiusmarquis not sure if you saw my last comment, but I'm wondering how to reproduce this. And also the PR will need to be rebased. Hope you had some happy holidays! |
It's still present on sapper 0.28.10. I also tested 2.29.0 real quick in I can still reproduce it quite easily on a fresh sapper setup: body {
color: green;
} import the file inside <script lang="ts">
import '../css/test.css';
import Nav from '../components/Nav.svelte';
export let segment: string;
</script>
… Change body {
color: red;
} |
Describe the bug
When you are changing the contents of an imported css in dev, you will see the changes immediately, but after a split second the page will be reloaded with the previous version. This is most likely because the js files file name (e.g.
my-component-{hash}.js
) will remain the same even though the correspondingmy-component-{hash}.css
changed. My guess is that the css file gets updated correctly, which will be applied immediately, but then a (unnecessary) page reload get's triggered. Because the js files hash is still the same even though the css contents changed (maybe because of theinject_css
stuff happening on top of the rollup build pipeline?), the service worker will provide an old, cached version of that js file.To Reproduce
In Browser dev tools:
after changing
src/styles/test.css
contents and "automated" page reload (wrong, still same css file hash)After "manual" page reload without any further css content change (correct css file hash)
Expected behavior
I think it would already be resolved if the page wouldn't reload on imported css change. The Service worker cache would be "out of sync" but that shouldn't have any side effects, I guess.
Information about your Sapper Installation:
Severity
It's annoying because you always have to manually reload the page after the unnecessary "automated" page reload
The text was updated successfully, but these errors were encountered: