Skip to content
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

Hugo server - Race conditon/timing issue when using generated css in html #12532

Open
hlpmenu opened this issue May 23, 2024 · 5 comments
Open

Comments

@hlpmenu
Copy link

hlpmenu commented May 23, 2024

What version of Hugo are you using (0.126.1)?

$ hugo version:
0.125.x and 0.126.x

Does this issue reproduce with the latest release?

Yes

Setup

Hugo 1.125/126
PostCss
Node 22

Issue

When using hugo pipes to process/generate a css file, and then using the css file in the html, since 0.125+ hugo tries to render the html pages before the css has ben processed, causing any change in a file detected by livereload to cause hugo server to fail, needing to be manually restarted.

This is due to the resource trying to be accessed not yet existing with message

Rebuild failed: render: failed to render pages: render of "page" failed: "/REDACTED/file.html:4:3": execute of template failed at <partial "head-content.html" .>: error calling partial: "/REDACTED/file2.html:114:27": execute of template failed at <$processedCSS.Content>: error calling Content: file does not exist

Hugo server is ran like:

hugo server --noHTTPCache --disableFastRender --ignoreCache --gc

Restarting hugo server fixes it, and its only when livereload triggers a refresh.

Example:
htmlfile.html

{{/* Combine, purge, minify and cssnano these css files */}}
{{ $twCSS := resources.Get "assets/css/file1.css"}}
{{ $mainCSS := resources.Get "assets/css/main.css" }}
{{ $tailwindDevCSS := resources.Get "assets/css/file2.css"}}
{{ $mdCSS := resources.Get "assets/css/markdown.css" }}
{{ $gradiaCSS := resources.Get "assets/css/file3.css"}}
{{ $combinedCSS := slice  $file1 $file2 $file3 $mainCSS $mdCSS | resources.Concat "assets/css/outputfilename.css" }}
{{ $processedCSS := $combinedCSS | resources.PostCSS | fingerprint }}

Inlining the css in the same file:

<style keep>

{{printf "%s" $processedCSS.Content | safeCSS}}

</style>

Fix

I havent had time to look trough the code but the issue started from 0.125+ and is only appearing when running hugo server and is consistently happening on every change livereload detects. Does disablefastrendersomehow not cause a full reload?

@jmooring
Copy link
Member

Please edit your description to make it legible.

When posting code, configuration, or data, please wrap the text within backticks or use the </> button in the menu.

```
my code
```

@hlpmenu
Copy link
Author

hlpmenu commented May 23, 2024

Please edit your description to make it legible.

When posting code, configuration, or data, please wrap the text within backticks or use the </> button in the menu.

my code

Sorry, pasted it and the backticks were not kept

@jmooring
Copy link
Member

Out of curiosity, what happens if you disable PostCSS when running in development mode?

@hlpmenu
Copy link
Author

hlpmenu commented May 23, 2024

Out of curiosity, what happens if you disable PostCSS when running in development mode?

So, i did some testing, and removing the postCSS pipe/transform dident do anythng.

However, removing "| fingerprint" DOES fix it.

So:
fingerprint + postcss = fails on rebuild
postcss only = rebuilds as it should

@bep bep added this to the v0.127.0 milestone May 29, 2024
@loveminimal
Copy link

I use scss to gen css , and it has the same problem, like this:

image

Now , I set back to v0.100.2 .

@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants