fix(adapter): evaluate client reference manifests as the installed Next.js does

SO
2d ago
+257-30

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 runInNewContext context, including process.
  • 16.5: Next.js evaluates with vm.compileFunction(content, ['globalThis', 'process'], …)(manifestGlobal, { env }) and returns manifestGlobal (vercel/next.js#101787), so process is not in it.
  • This adapter: the build still evaluated the 16.4 way, so on 16.5 it shipped a process key. 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 own evalManifest failed at 16.5.0.

Change

  • manifestEvaluationOf(projectDir) works out once per build which form the installed load-manifest.external.js uses. 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.
  • evaluateManifestScript takes 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 (the next-16-4-5 alias):
    • manifestEvaluationOf picks the right form.
    • Scripts that write globalThis.__RSC_MANIFEST or read process.env.NEXT_DEPLOYMENT_ID give output toStrictEqual to that release's real evalManifest.
    • The patch-rewritten loader, given the shipped JSON, returns what the unpatched evalManifest returns.
  • vitest (manifests, build-paths, external-pages-api-dist, native-graph, split): 62 pass.
  • tsc, eslint, oxfmt and check: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).


Devin Review


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 the load-manifest patch rewrites by, so the two cannot disagree about a given Next.js.
  • collectManifests now asks the installed Next.js for its form once per build; evaluateManifestScript takes 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 evalManifest of 16.5.0 and 16.4.5.

Migration

  • collectManifests now takes an optional evaluation form, and evaluateManifestScript a required fourth argument; pass await 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.