cloudflare/vinext

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

已關閉

#1,456 建立於 2026年5月22日

 (0 則留言) (0 個反應) (0 位負責人)TypeScript (385 個分叉)github user discovery
adapter-api-e2ehelp wanted

倉庫指標

星標
 (8,633 顆星)
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.

貢獻者指南