cloudflare/vinext

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

Closed

#1,456 opened on May 22, 2026

 (0 comments) (0 reactions) (0 assignees)TypeScript (371 forks)github user discovery
adapter-api-e2ehelp wanted

Repository metrics

Stars
 (8,563 stars)
PR merge metrics
 (Avg merge 1d 1h) (462 merged PRs in 30d)

Description

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