cloudflare/vinext

Pages Router: `__NEXT_DATA__` inline JSON script tag missing from SSR HTML

Geschlossen

#1.456 geöffnet am 22.05.2026

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (384 Forks)github user discovery
adapter-api-e2ehelp wanted

Repository-Metriken

Stars
 (8.625 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 1h) (462 gemergte PRs in 30 T)

Beschreibung

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-22).

Problem

Pages Router SSR responses do not emit the inline <script id="__NEXT_DATA__" type="application/json">{...}</script> element. Tests using cheerio to call JSON.parse($('#__NEXT_DATA__').text()) get SyntaxError: Unexpected end of JSON input because the element is missing or empty. This blocks ~10 assertions in getserversideprops/test/index.test.ts covering gssp prop serialization, query reflection, and direct-visit dynamic routes.

SyntaxError: Unexpected end of JSON input
  at JSON.parse

Estimated Impact

~10 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/getserversideprops/test/index.test.ts (10 failures)

Recommendation

  1. Reproduce first in vinext's own test suite. Add a test fetching a Pages Router gssp page and asserting #__NEXT_DATA__ script content parses as JSON with props.pageProps populated.

  2. Study the Next.js implementation. Search .nextjs-ref/packages/next/src/server/render.tsx and next-data.tsx for how __NEXT_DATA__ is serialised into the SSR HTML.

  3. Emit __NEXT_DATA__ from the Pages Router SSR renderer. After Pages Router SSR completes, inject a <script id="__NEXT_DATA__" type="application/json"> containing props, page, query, buildId, runtimeConfig, etc. This is what next/router hydration and getInitialProps rely on, and it is what the test suites assert.

  4. Coordinate with the hydration fix. Without __NEXT_DATA__ the client bundle cannot pick up props, which intersects with the separate pages-router-hydration-no-client-bundle failure.

Contributor Guide