perf(search): load Pagefind lazily on first open; build the index in dev and build#3340
Open
Vidminas wants to merge 2 commits into
Open
perf(search): load Pagefind lazily on first open; build the index in dev and build#3340Vidminas wants to merge 2 commits into
Vidminas wants to merge 2 commits into
Conversation
Pagefind was imported eagerly in the search modal's init(), so its index loaded on every page view even when search was never opened. Move the import into an idempotent ensurePagefind() that runs when the modal first opens (and is awaited by search() to cover a user typing before that load finishes). Also build the Pagefind index in the academic-cv starter's `dev` script so search works under `pnpm dev` (mirrors the monorepo dev harness; output goes to the already-gitignored static/pagefind). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extend the dev-time index build (previously only academic-cv) to every starter, and inline the Pagefind call in both `dev` and `build` instead of the `pnpm run pagefind` indirection: dev: hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server ... build: hugo --minify && pagefind --site public `dev` writes the index into static/ so `hugo server` serves it; `build` writes it straight into the deployed public/pagefind. The `pagefind` script is kept because each starter's netlify.toml still calls `pnpm run pagefind`. The `starter` base template keeps its `|| true` fault-guard, scoped in a subshell so it can't mask a Hugo failure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
β Deploy Preview for academic-demo failed. Why did it fail? β
|
Author
|
Builds fail due to Hugo 0.162.0 incompatibility, which is addressed in #3329 |
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.
π What type of change is this?
π― What is the purpose of this change?
The search modal imported Pagefind eagerly in
init(), sopagefind.jsand the index werefetched on every page view, even for visitors who never open search. (The current try/catch +
assetPathsalready make a missing index degrade gracefully β this is the remaining perf/ergonomicsrefinement.)
Changes:
Lazy load (engine). Move the import into an idempotent
ensurePagefind()that runs the firsttime the search modal opens (via the existing
$store.search.openwatcher), and isawaited bysearch()so typing before the load finishes still works. Net: the index is fetched on firstsearch-open, not on page load.
Build the index in
devandbuild(all starters). Inline the Pagefind call in everystarter's
devandbuildscripts, replacing thepnpm run pagefindindirection so each scriptis explicit and self-contained:
dev:hugo && pagefind --site public --output-subdir ../static/pagefind && hugo server β¦β builds the index into the already-gitignored
static/pagefind/sohugo serverserves it,making search work under
pnpm dev(mirrors the monorepo dev harness inview-starter-dev.sh).build:hugo --minify && pagefind --site publicβ writes the index straight into thedeployed
public/pagefind(the standard location; unchanged behaviour, just inlined).The standalone
pagefindscript is kept because each starter'snetlify.tomlstill callspnpm run pagefind. Thestarterbase template wraps its2>/dev/null || truefault-guard in a subshell βhugo && (pagefind β¦ || true) && hugo serverβ so it tolerates only a Pagefind failure. Inlinedbare,
sh's equal&&/||precedence would let|| truealso swallow a failed Hugo build andstart the server on broken output.
Verified: the built search script has exactly one
await import(...)(insideensurePagefind),init()no longer imports eagerly, the open-watcher callsensurePagefind(), and the emitted JSpasses
node --check. All nine starters'package.jsonremain valid JSON, and Pagefind's outputlocations are confirmed empirically β
--output-subdir ../static/pagefindwrites tostatic/pagefind/(dev, served byhugo server) and the default--site publicwrites topublic/pagefind/(build, the deployed output).πΈ Screenshots or Screencast (if applicable)
n/a
βΉοΈ Documentation Check
π Contributor Agreement
Thank you for your contribution!