Pages Router: `__NEXT_DATA__` inline JSON script tag missing from SSR HTML
#1,456 opened on May 22, 2026
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
mainvs Next.jsv16.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
-
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 withprops.pagePropspopulated. -
Study the Next.js implementation. Search
.nextjs-ref/packages/next/src/server/render.tsxandnext-data.tsxfor how__NEXT_DATA__is serialised into the SSR HTML. -
Emit
__NEXT_DATA__from the Pages Router SSR renderer. After Pages Router SSR completes, inject a<script id="__NEXT_DATA__" type="application/json">containingprops,page,query,buildId,runtimeConfig, etc. This is whatnext/routerhydration andgetInitialPropsrely on, and it is what the test suites assert. -
Coordinate with the hydration fix. Without
__NEXT_DATA__the client bundle cannot pick up props, which intersects with the separatepages-router-hydration-no-client-bundlefailure.