Skip to content

Fix pagefind site search by preloading window.pagefind - #2399

Merged
markerikson merged 1 commit into
masterfrom
docs/fix-pagefind-search
Sep 19, 2026
Merged

markerikson merged 1 commit into
masterfrom
docs/fix-pagefind-search

Conversation

@markerikson

Copy link
Copy Markdown
Contributor

Problem

Site search opens and accepts input but never shows results. @getcanary/web's pagefind provider does

pagefind = await import(/* @vite-ignore */ /* webpackIgnore: true */ this.options?.path ?? "/pagefind/pagefind.js")

The bundler inlines that dynamic import instead of leaving it as a browser import (this is the build-time "Critical dependency: the request of a dependency is an expression" warning). At runtime it throws MODULE_NOT_FOUND: Cannot find module '/pagefind/pagefind.js', the provider logs Failed to import pagefind at info level and gives up. Confirmed on the live site: window.pagefind is undefined and results are empty, while a manual import('/pagefind/pagefind.js') returns hits, so the index itself is fine.

Fix

The provider checks window.pagefind first and skips the import when it exists. Add a headTags module script that loads /pagefind/pagefind.js and assigns it to window.pagefind. 12-line config change, no dependency changes.

Same fix as reduxjs/redux#4949, where the deploy preview confirmed search works again.

Verification

  • pnpm build succeeds; built HTML contains the preload script.
  • Check the Netlify deploy preview: open search, type a term, results should appear.

@getcanary/web's pagefind provider does a dynamic import of /pagefind/pagefind.js
with a webpackIgnore comment. The bundler inlines it anyway, so the import fails
at runtime with MODULE_NOT_FOUND and search returns no results. The provider
uses window.pagefind when present, so load it from a head module script.

Same fix as reduxjs/redux#4949.
@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 37.1 kB

ℹ️ View Unchanged
Filename Size
dist/cjs/index.js 140 B
dist/cjs/react-redux.development.cjs 9.66 kB
dist/cjs/react-redux.production.min.cjs 3.77 kB
dist/react-redux.browser.mjs 3.57 kB
dist/react-redux.legacy-esm.js 10.1 kB
dist/react-redux.mjs 9.23 kB
dist/rsc.mjs 567 B

compressed-size-action

@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/react-redux@bc4f1c1 -D
yarn add https://pkg.pr.new/react-redux@bc4f1c1.tgz -D
pnpm add https://pkg.pr.new/react-redux@bc4f1c1.tgz -D
bun add https://pkg.pr.new/react-redux@bc4f1c1.tgz -D

commit: bc4f1c1

@netlify

netlify Bot commented Sep 19, 2026

Copy link
Copy Markdown

Deploy Preview for react-redux-docs ready!

Name Link
🔨 Latest commit bc4f1c1
🔍 Latest deploy log https://app.netlify.com/projects/react-redux-docs/deploys/6aae0a7b98b6c0107548d551
😎 Deploy Preview https://deploy-preview-2399--react-redux-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@markerikson
markerikson merged commit 0b4e333 into master Sep 19, 2026
49 of 51 checks passed
@markerikson
markerikson deleted the docs/fix-pagefind-search branch September 19, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant