fix(adapter): evaluate client reference manifests as the installed Next.js does
SO
2d ago+257+257+012345678901234567890123456789-30-30-01234567890123456789
Summary
The adapter evaluates each client reference manifest at build time and ships the result as JSON, so the Function never needs node:vm. That result has to be exactly what the installed Next.js's evalManifest returns. On 16.5 it was not.
- 16.4 and earlier: Next.js returned the whole
runInNewContextcontext, includingprocess. - 16.5: Next.js evaluates with
vm.compileFunction(content, ['globalThis', 'process'], …)(manifestGlobal, { env })and returnsmanifestGlobal(vercel/next.js#101787), soprocessis not in it. - This adapter: the build still evaluated the 16.4 way, so on 16.5 it shipped a
processkey. The patched loader deleted that key at request time, so requests were already answered correctly, but the shipped JSON was not what Next.js evaluates. A parity test that compares every built manifest with Next.js's ownevalManifestfailed at 16.5.0.
Change
manifestEvaluationOf(projectDir)works out once per build which form the installedload-manifest.external.jsuses. It applies the same test the load-manifest patch rewrites by,evaluatesInFunction, so the build and the patch cannot disagree about a given Next.js.evaluateManifestScripttakes that form and ships exactly what the form returns:{ __RSC_MANIFEST }on 16.5, and the whole context before it.- The 16.5 loader now takes the shipped object as it is, with no
delete manifestGlobal.process. The older loader is unchanged.
Verification
- New
test/manifests.test.ts, run against the installed 16.5.0 and against 16.4.5 (thenext-16-4-5alias):manifestEvaluationOfpicks the right form.- Scripts that write
globalThis.__RSC_MANIFESTor readprocess.env.NEXT_DEPLOYMENT_IDgive outputtoStrictEqualto that release's realevalManifest. - The patch-rewritten loader, given the shipped JSON, returns what the unpatched
evalManifestreturns.
- vitest (manifests, build-paths, external-pages-api-dist, native-graph, split): 62 pass.
tsc, eslint, oxfmt andcheck:vocabulary: clean.
evaluateManifestScript now takes the form as a fourth argument. A caller outside this repository has to pass it, for example await manifestEvaluationOf(projectDir).
Summary by cubic
The build now evaluates client reference manifests the way the installed Next.js does, so on Next.js 16.5 the shipped JSON no longer has a process key, and the patched loader stops deleting it at request time. Requests were already answered correctly; only the shipped bytes differed from what Next.js evaluates.
manifestEvaluationOf(projectDir)detects the evaluation form using the same test theload-manifestpatch rewrites by, so the two cannot disagree about a given Next.js.collectManifestsnow asks the installed Next.js for its form once per build;evaluateManifestScripttakes that form and ships exactly what it returns:{ __RSC_MANIFEST }on 16.5, the whole context before it.- New tests compare both forms against the real
evalManifestof 16.5.0 and 16.4.5.
Migration
collectManifestsnow takes an optionalevaluationform, andevaluateManifestScripta required fourth argument; passawait manifestEvaluationOf(projectDir)where needed.
Summary by CodeRabbit
- Bug Fixes
- Improved compatibility with different Next.js versions when processing build manifests, helping builds complete with the expected manifest data.
- Corrected handling of deployment identifiers and manifest values across supported evaluation modes, including values that cannot be safely serialized.
- Preserved static-export behavior, which continues to use an empty manifest list.