cloudflare/vinext

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

已关闭

#1,456 创建于 2026年5月22日

 (0 条评论) (0 个反应) (0 位负责人)TypeScript (384 个派生)github user discovery
adapter-api-e2ehelp wanted

仓库指标

星标
 (8,625 个星标)
PR 合并指标
 (平均合并 1天 1小时) (30 天内合并 462 个 PR)

描述

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.

贡献者指南