Pages Router: custom `_document` (`getInitialProps` / `renderPage` enhancers) not implemented
#1,468 建立於 2026年5月22日
倉庫指標
- Star
- (8,120 star)
- PR 合併指標
- (平均合併 1天 1小時) (30 天內合併 462 個 PR)
描述
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
Tests for Pages Router custom _document.js fail because vinext does not run Document.getInitialProps or honor ctx.renderPage({ enhanceApp, enhanceComponent }). As a result <Document> does not receive the expected html prop, custom enhancers never run, and nonce/crossOrigin attributes are missing on emitted scripts.
Document.getInitialProps did not run; renderPage enhanceApp/enhanceComponent did not run
Estimated Impact
~8 test failures across the deploy suite.
Affected Test Suites
test/e2e/app-document/rendering.test.ts(8 failures)
Recommendation
-
Reproduce first in vinext's own test suite. Add a Pages Router app with a custom
_document.tsxexportinggetInitialPropsplusrenderPage({ enhanceApp, enhanceComponent }). Assert each hook runs and the produced HTML reflects it. -
Study
.nextjs-ref/packages/next/src/server/render.tsx. Understand the_documentlifecycle: getInitialProps withctx.renderPage, the enhanceApp/enhanceComponent contract, and how nonce/crossOrigin propagate to emitted<script>tags. -
Implement the Pages Router
_documentpipeline. RunDocument.getInitialProps, supportctx.renderPage({ enhanceApp, enhanceComponent }), propagatenonceandcrossOriginto script tags.