Repository navigation
fix(website): index prerendered HTML from Next's adapter route cache - #697
Merged
Merged
Conversation
`next@16.4.0` (vercel/next.js#99482) writes prerendered app HTML to `.next/server/route-cache/APP_PAGE/<sha256(source route)>/$/` whenever a deployment adapter is configured. Vercel's `@vercel/next` builder sets `NEXT_ADAPTER_PATH`, so on Vercel `.next/server/app` no longer contains any HTML and `pagefind --site .next/server/app` fails with "Found 0 files" / "Pagefind was not able to build an index", exiting 1. Local and CI builds have no adapter and still prerender to `.next/server/app`, which is why the failure only showed up in the Vercel deployment. Replace the CLI call with a small script on Pagefind's Node API that indexes `.next/server/app` plus every `route-cache/APP_PAGE/*/$` root that exists. URLs are relative to each root, so search results are unchanged (`/`, `/guide.html`, `/examples/activity.html`, ...), and the script still fails the build when no HTML is found. Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
There was a problem hiding this comment.
🟢 Approval recommended
The implementation correctly handles both Next.js output layouts with appropriate failure reporting.
0 open findings
What changed in this PR
Updates website search indexing to support Next.js 16.4 adapter route-cache output while preserving local builds.
Changes:
- Adds Pagefind discovery and indexing across standard and adapter output roots.
- Runs the new script after website builds.
- Includes
.mtsscripts in TypeScript analysis.
| File | Description |
|---|---|
website/scripts/pagefind.mts |
Discovers prerendered HTML roots and builds the Pagefind index. |
website/package.json |
Uses the new postbuild script. |
website/tsconfig.json |
Includes .mts files in type checking. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch was successfully deployed
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.
Description
The
Vercel – react-rxdeployment of the docs site fails oncurrentsince #694:next buildsucceeds, thenpagefind --site .next/server/appreportsFound 0 files matching **/*.{html}and exits 1 with "Pagefind was not able to build an index".Root cause. #694 resolved
next^16.3.6→16.4.0(the lockfile-only hold from #684 could not survive the next lockfile refresh).next@16.4.0is the first stable release with vercel/next.js#99482 "Scope response cache keys to their source route": when a deployment adapter is configured, the export worker writes each prerendered page to.next/server/route-cache/APP_PAGE/<sha256(source route)>/$/<pathname>.html(useScopedBuildArtifactsinnext/dist/export/worker.js) instead of.next/server/app/<pathname>.html. Vercel's@vercel/nextbuilder setsNEXT_ADAPTER_PATH(adapter builds fornext >= 16.2.0-canary.28), so on Vercel.next/server/appcontains only the compiled route modules and no HTML. Local and CI builds have no adapter and still prerender to.next/server/app, which is whynext buildkept passing everywhere except the Vercel deployment. The layout is unchanged on Next canary, so this is the new permanent output for adapter builds, not a regression that will be reverted.Fix.
postbuildnow runswebsite/scripts/pagefind.mts, which uses Pagefind's Node API to index.next/server/appplus every.next/server/route-cache/APP_PAGE/*/$root that exists, then writespublic/_pagefindas before. Pagefind derives URLs relative to each root, so the index content is identical to what the CLI produced before 16.4 (/,/guide.html,/examples/activity.html, … — Nextra strips.html). The script still fails the build when no HTML is found anywhere, and prints which roots it indexed so a future layout change is visible in the build log.Why not pin
next. Reverting to 16.3.6 only defers this to the next bump (the #684 hold lasted hours), holds back security patches, and the route-cache layout is where the Vercel adapter now reads prerendered output from. Pointing Pagefind at where the HTML actually lives is the durable fix; a single--sitedirectory cannot express it because the root is hashed and differs between adapter and non-adapter builds, hence the small script.The
tsconfig.jsonchange only adds**/*.mtstoincludeso Oxlint's type-aware lint sees@types/nodefor the script..mtsis used so Node loads it as ESM withoutMODULE_TYPELESS_PACKAGE_JSONwarnings, sincewebsite/package.jsonhas no"type": "module".What to review
website/scripts/pagefind.mts— the root discovery (.next/server/appandroute-cache/APP_PAGE/<hash>/$), error handling (createIndex/addDirectory/writeFileserrors, and the explicit "no prerendered HTML" failure), and the summary line. 41 lines, oneno-consoledisable for the summary.website/package.json—postbuildruns the script withnode(Node ≥ 22.18 strips types natively; theprebuildtsdown step already requires that on every build host).website/tsconfig.json—**/*.mtsadded toinclude.Suggested merge: rebase (single commit).
Testing
No automated test for a build script; verified by running
pnpm run buildinwebsite/withnext@16.4.0from the current lockfile, in both layouts:Pagefind indexed 24 from .next/server/app into public/_pagefind, exit 0,pagefind-entry.jsonreportspage_count: 22.NEXT_ADAPTER_PATH=<no-op adapter>: before this change,pagefind --site .next/server/app→Found 0 files matching **/*.{html}→Pagefind was not able to build an index→ exit 1 (the exact Vercel failure). After:Pagefind indexed 1 from …/APP_PAGE/1ac71f…/$, 1 from …/APP_PAGE/41da0e…/$, 22 from …/APP_PAGE/fbc75e…/$ into public/_pagefind, exit 0.en_155874b525, 22 pages); the decoded fragments list/,/guide.html,/reference.html,/examples/*.html,/migrate/*.htmlwith noroute-cacheprefix..next/server/appexits 1 withPagefind found no prerendered HTML in .next/server/appand writes nothing.pnpm lint,pnpm knipandoxfmt --checkpass.Vercel – react-rxcheck passes ("Deployment has completed"), the preview serves/_pagefind/pagefind-entry.jsonwithpage_count: 22, and a Pagefind query foruseObservableagainst the preview's index returns 20 results whose URLs (/reference,/guide,/examples/simple,/migrate/v4-to-v7, …) all respond HTTP 200.