"Failed to render… error calling Defer" on 0.162

Hello folks,

Since bumping to version 0.162 my site fails to build. I dropped back to 0.161 and it works without a problem. Here’s the error output:

building site: render: [en v1.0.0 guest] failed to render pages: render of "/chassis/sv" failed:
"layouts/baseof.html:7:5": execute of template failed:
template: chassis/term.html:7:5: executing "chassis/term.html" at <partial "head.html" .>:
error calling partial: "layouts/_partials/head.html:21:5": execute of template failed:
template: _partials/head.html:21:5: executing "_partials/head.html" at <partialCached "head/css.html" .>:
error calling partialCached: "layouts/_partials/head/css.html:1:18":
execute of template failed: template: _partials/head/css.html:1:18:
executing "_partials/head/css.html" at <templates.Defer>:
error calling Defer:
templates.Defer cannot be used inside a partialCached partial; use partial instead, or move templates.Defer to the calling template

Has something changed between 0.161 and 0.162 that means this partial is no longer valid (obviously I can see the offending line) or is it a bug that shouldn’t happen (and I should report on GH)?

Here’s the CSS partial:

{{ with (templates.Defer (dict "key" "global")) }}
  {{ with resources.Get "css/styles.css" -}}
    {{ $opts := dict
      "inlineImports" true
      "optimize" (not hugo.IsDevelopment)
    }}
    {{ with . | css.TailwindCSS $opts -}}
      {{ if hugo.IsDevelopment -}}
        <link rel="stylesheet" href="{{ .RelPermalink }}" />
      {{ else -}}
        {{ with . | minify | fingerprint -}}
          <link
            rel="stylesheet"
            href="{{ .RelPermalink }}"
            integrity="{{ .Data.Integrity }}"
            crossorigin="anonymous"
          />
        {{ end -}}
      {{ end -}}
    {{ end -}}
  {{ end -}}
{{ end -}}

Many thanks!

executing “_partials/head.html” at <partialCached “head/css.html” .>:

The simplest change would be to replace partialCached with partial in head.html.

  • There was a issue fixed that in short was about templates.Defer creating error situation when used inside partialCached in some situations, so we added validation.
  • Note that templates.Defer is also caching the result, so in most cases the surrounding partialCache caching is superflous.

That’s most helpful to know @bep - thank you for clarifying :folded_hands:

Also, see steps 4 and 5 here css.TailwindCSS

Thanks @bandulu. This is a timely reminder for one to check docs for updates. That all changed in this commit, after I’d built the partial (with the original syntax). So my syntax was correct but is now out of date :smiley: