Skip to content

fix: publish the search index on Hugo < 0.164 (avoid the PostProcess/Defer clash)#310

Merged
markdumay merged 1 commit into
mainfrom
styles/flexsearch-defer-fix
Jul 18, 2026
Merged

fix: publish the search index on Hugo < 0.164 (avoid the PostProcess/Defer clash)#310
markdumay merged 1 commit into
mainfrom
styles/flexsearch-defer-fix

Conversation

@markdumay

Copy link
Copy Markdown
Contributor

The bug

On Hugo < 0.164, a page that uses resources.PostProcess silently prevents that page's
templates.Defer blocks from executing (Hugo 0.164 fixed this coexistence). The Hinode theme's
production stylesheet always pipes CSS through … | fingerprint | resources.PostProcess — and
that is load-bearing: it is how css.PostCSS is deferred to post-build so PurgeCSS reads a
complete hugo_stats.json. This partial's search index uses templates.Defer. On Hugo
0.146–0.163 the two collide: the deferred index never publishes and its raw
__hdeferred/…__d= placeholder leaks into the rendered navbar search box.

It's masked in this repo's / Hinode's own CI because those build with Hugo 0.164.

Minimal repro (no Hinode, no flexsearch): a <head> doing
resources.FromString | minify | fingerprint | resources.PostProcess plus a templates.Defer
block in the body → on 0.161 the deferred block never runs and its token leaks; on 0.164 it's clean.

The fix

Version-gate the publisher in assets/search-index.html:

  • Hugo ≥ 0.164: unchanged — templates.Defer (no serial render).
  • Hugo < 0.164: publish the index eagerly instead, guarded to run once per language via
    site.Store. Correct output; the cost is the serial-render stall that templates.Defer was
    introduced to avoid — paid only on old Hugo.

hugo.Version.Compare "0.164.0" is used for a semantic (not string) version test.

Evidence (Hinode exampleSite, hugo --gc --minify)

Hugo search index __hdeferred leak
0.146.7 published 0
0.147.6 published 0
0.161.1 (eager) published 0
0.164.0 (deferred) published 0
  • 0.161 (eager) vs 0.164 (deferred): index byte-identical (550,561 B) — the eager path produces
    exactly the deferred output.
  • The small 0.147.6-vs-0.164 index delta is cross-Hugo-version content rendering
    (.Plain/.Summary), not the fix.

Held for review. (Found while adopting the Hinode v3.6.0 styles pipeline in the starter template,
whose deploy preview builds with Hugo 0.158/0.161 and surfaced the leak.)

…Defer clash)

On Hugo < 0.164 a page that uses resources.PostProcess silently prevents that
page's templates.Defer blocks from executing. Hinode's production stylesheet
always uses resources.PostProcess (it is how css.PostCSS is deferred so PurgeCSS
reads a complete hugo_stats.json), so the deferred search index never published
and its raw __hdeferred placeholder token leaked into the navbar search box.

Version-gate the publisher: keep templates.Defer on Hugo >= 0.164 (no serial
render), and on older Hugo publish the index eagerly instead, guarded to run
once per language via site.Store. Correct on both paths at the cost of the
serial-render stall on old Hugo that Defer was introduced to avoid.

Verified on the exampleSite across Hugo 0.146.7 / 0.147.6 / 0.161.1 / 0.164.0:
no placeholder leak on any version; index published on all; the eager (0.161)
and deferred (0.164) indexes are byte-identical (550,561 B).
@markdumay
markdumay merged commit e45100b into main Jul 18, 2026
8 checks passed
@markdumay

Copy link
Copy Markdown
Contributor Author

🎉 This PR is included in version 5.1.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant