fix: publish the search index on Hugo < 0.164 (avoid the PostProcess/Defer clash)#310
Merged
Merged
Conversation
…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).
Contributor
Author
|
🎉 This PR is included in version 5.1.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
On Hugo < 0.164, a page that uses
resources.PostProcesssilently prevents that page'stemplates.Deferblocks from executing (Hugo 0.164 fixed this coexistence). The Hinode theme'sproduction stylesheet always pipes CSS through
… | fingerprint | resources.PostProcess— andthat is load-bearing: it is how
css.PostCSSis deferred to post-build so PurgeCSS reads acomplete
hugo_stats.json. This partial's search index usestemplates.Defer. On Hugo0.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>doingresources.FromString | minify | fingerprint | resources.PostProcessplus atemplates.Deferblock 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:templates.Defer(no serial render).site.Store. Correct output; the cost is the serial-render stall thattemplates.Deferwasintroduced 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)__hdeferredleakexactly the deferred output.
(
.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.)