Skip to content

Pages Router: _next/data JSON endpoint not implemented #1330

Description

@james-elicx

This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.2.6, 2026-05-20).

Problem

The Pages Router production server does not handle /_next/data/[buildId]/[page].json requests. In Next.js, client-side navigations in the Pages Router fetch page data from this endpoint, which returns a JSON object like {"pageProps":{"message":"Hello"}}.

When vinext receives these requests, it either:

  1. Returns 404 — does not recognize the _next/data URL pattern
  2. Returns HTML — serves the full rendered page instead of the JSON data envelope

Additionally, middleware URL normalization is missing: middleware sees the raw /_next/data/.../page.json path instead of the normalized page path (e.g., /page).

FetchError: invalid json response body at
  http://127.0.0.1:33447/_next/data/e6777d6d-.../es/about.json
  reason: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
Expected: "/send-url/"
Received: "/_next/data/49d16a23-.../send-url.json"

Estimated Impact

~30 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/middleware-trailing-slash/test/index.test.ts
  • test/e2e/middleware-general/test/index.test.ts
  • test/e2e/middleware-general/test/node-runtime.test.ts
  • test/e2e/middleware-rewrites/test/index.test.ts
  • test/e2e/middleware-redirects/test/index.test.ts
  • test/e2e/middleware-redirects/test/node-runtime.test.ts
  • test/e2e/edge-pages-support/index.test.ts
  • test/e2e/prerender.test.ts

Recommendation

  1. Reproduce first in vinext's own test suite. Add a test case that makes a request to /_next/data/[buildId]/[page].json on a Pages Router app and asserts it returns JSON with the correct pageProps. Confirm it fails before implementing the fix.

  2. Implement a _next/data route handler in server/prod-server.ts. Intercept requests matching /_next/data/[buildId]/[page].json, extract the page path, call the page's getServerSideProps/getStaticProps, and return the result as { pageProps: ... } JSON.

  3. Implement URL normalization in the middleware pipeline. Before passing requests to middleware, strip the /_next/data/[buildId]/ prefix and .json suffix so middleware sees the canonical page path (e.g., /send-url/ instead of /_next/data/.../send-url.json).

  4. Check dev/prod parity. Ensure server/dev-server.ts also handles data requests consistently.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions