See the fix in #15188.
This has been an issue since we added this feature, but we haven't noticed it (or gotten reports about it) because the common setup is to set up the entire chain before starting to use it:
{{- with . | css.Build $opts }}
{{- if hugo.IsDevelopment }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{- else }}
{{- with . | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}">
{{- end }}
{{- end }}
{{- end }}
In the above:
.RelPermalink triggers the transformation of the entire chain in a streaming way.
With the recently added .Data.Artifacts in css.Build I discovered this issue by accident when doing something ala:
{{- with . | css.Build $opts }}
{{ range .Data.Artifacts }}
{{ if eq .MediaType.MainType "font" }}
<link rel="preload" href="{{ .RelPermalink }}" as="font" type="{{ .MediaType.Type }}">
{{ end }}
{{ end }}
{{- if hugo.IsDevelopment }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{- else }}
{{- with . | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}">
{{- end }}
{{- end }}
{{- end }}
In the above:
.Data triggers the css.Build transformation.
- Then
fingerprint starts a new transformation with correct .Content, but wrongly including the full chain, including css.Build
The above could be rewritten to the below and it would work as expected:
{{- with . | css.Build $opts }}
{{- if hugo.IsDevelopment }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{- else }}
{{- with . | fingerprint }}
{{ range .Data.Artifacts }}
{{ if eq .MediaType.MainType "font" }}
<link rel="preload" href="{{ .RelPermalink }}" as="font" type="{{ .MediaType.Type }}">
{{ end }}
{{ end }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}">
{{- end }}
{{- end }}
{{- end }}
{{- end }}
See the fix in #15188.
This has been an issue since we added this feature, but we haven't noticed it (or gotten reports about it) because the common setup is to set up the entire chain before starting to use it:
In the above:
.RelPermalinktriggers the transformation of the entire chain in a streaming way.With the recently added
.Data.Artifactsincss.BuildI discovered this issue by accident when doing something ala:In the above:
.Datatriggers thecss.Buildtransformation.fingerprintstarts a new transformation with correct.Content, but wrongly including the full chain, includingcss.BuildThe above could be rewritten to the below and it would work as expected: