zola icon indicating copy to clipboard operation
zola copied to clipboard

`get_file_hash` doesn't update when running `zola serve` and editing a SCSS file.

Open DannyJJK opened this issue 2 years ago • 5 comments

Bug Report

get_file_hash doesn't update when running zola serve and editing a SCSS file.

Environment

Zola version: 0.15.3

Expected Behavior

SCSS file recompiles, and CSS integrity hash gets updated, so it doesn't become invalid.

Current Behavior

Currently, the SCSS file recompiles, but the hash doesn't get updated, causing the styling not to load. The hash only gets updated when stopping zola serve and restarting.

Step to reproduce

Use an integrity hash on a compiled SCSS file like so:

<link rel="stylesheet" href="/main.css" integrity="sha512-{{ get_file_hash(path="main.css", sha_type=512, base64=true) | safe }}">

Run zola serve. Edit the SCSS file (in this case, main.scss) and save it. The SCSS file recompiles, but then the browser refuses to load the styling because the hash hasn't updated.

DannyJJK avatar Apr 02 '22 21:04 DannyJJK

You should have live reload on changes to the CSS, do you not get them? CSS changes do not re-trigger a templates rebuild, only the CSS+live reload.

Keats avatar Apr 03 '22 06:04 Keats

The CSS does update, but the browser will then refuse to display the styling because the hash no longer matches the updated file. I used to use the Hugo site builder which did update the hash on live reload, I guess I viewed this as a bug but it may be a feature request.

Of course I could remove the hash while developing and then re-add it once done, but this is a little jarring, unless there's a way I can automate it within the Tera template

DannyJJK avatar Apr 03 '22 10:04 DannyJJK

How do they update the hash while live reloading? They must either re-render the templates and disable the hash in the serve mode?

Keats avatar Apr 03 '22 18:04 Keats

I believe they re-render the template, perhaps checking for which templates contain the function which generates the integrity hash on the file that's been updated https://gohugo.io/hugo-pipes/fingerprint/

But I wouldn't mind disabling the hash in the serve mode. Do you know if that's currently possible? I'm happy with that approach

DannyJJK avatar Apr 03 '22 18:04 DannyJJK

I believe they re-render the template, perhaps checking for which templates contain the function which generates the integrity hash on the file that's been updated

In practice that would essentially be rendering the whole site for CSS files.

Do you know if that's currently possible? I'm happy with that approach

It's not currently possible but would be a simple way to solve it. It's not great to have different behaviours based on serve or build though :/

Keats avatar Apr 04 '22 13:04 Keats

This isn't just limited to SCSS files, also static files don't get their get_file_hash updated on reload.

orlp avatar Jan 15 '23 02:01 orlp