[PR #594] feat: implement next/document with class-based Document and getInitialProps support #695

Open
opened 2026-05-06 13:09:36 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/594
Author: @james-elicx
Created: 3/19/2026
Status: 🔄 Open

Base: mainHead: opencode/quiet-nebula


📝 Commits (5)

  • 8b4ab93 feat: implement next/document with class-based Document and getInitialProps support
  • 422b602 fix: address review comments on next/document getInitialProps
  • 38c4587 feat(pages-router): render error pages through custom _document with getInitialProps
  • d9509c4 feat(pages-router): implement App.getInitialProps and fix appProps propagation
  • 6cd668e fix(pages-router): inject client entry script and fix asset preloading

📊 Changes

18 files changed (+1050 additions, -129 deletions)

View changed files

📝 packages/vinext/src/client/entry.ts (+7 -3)
📝 packages/vinext/src/entries/pages-client-entry.ts (+2 -2)
📝 packages/vinext/src/entries/pages-server-entry.ts (+194 -16)
📝 packages/vinext/src/index.ts (+1 -1)
📝 packages/vinext/src/server/dev-server.ts (+181 -12)
📝 packages/vinext/src/server/middleware.ts (+21 -36)
📝 packages/vinext/src/server/prod-server.ts (+20 -0)
📝 packages/vinext/src/shims/app.ts (+68 -4)
📝 packages/vinext/src/shims/document.tsx (+61 -11)
📝 packages/vinext/src/shims/next-shims.d.ts (+86 -0)
📝 packages/vinext/src/shims/router.ts (+5 -1)
📝 playwright.config.ts (+3 -1)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+196 -18)
tests/e2e/pages-router-prod/document.spec.ts (+47 -0)
tests/e2e/pages-router/document.spec.ts (+48 -0)
📝 tests/fixtures/pages-basic/next-shims.d.ts (+74 -7)
📝 tests/fixtures/pages-basic/pages/_app.tsx (+7 -3)
📝 tests/fixtures/pages-basic/pages/_document.tsx (+29 -14)

📄 Description

Summary

  • Rewrites the next/document shim to export proper TypeScript types (DocumentContext, DocumentInitialProps) and a class-based Document base class with a default getInitialProps static method
  • Adds ambient declare module 'next/document' types to next-shims.d.ts so custom _document.tsx files type-check correctly
  • Wires getInitialProps into the Pages Router dev server via a new buildDocumentContext helper — custom documents can now augment document props (e.g. injecting a theme)
  • Updates the test fixture _document.tsx to use a class-based document with getInitialProps that adds a theme prop rendered as data-theme-prop on <body>
  • Adds a new E2E test (tests/e2e/pages-router/document.spec.ts) that verifies the custom document prop is present in the rendered HTML

Testing

  • PLAYWRIGHT_PROJECT=pages-router pnpm test:e2e tests/e2e/pages-router/document.spec.ts — 1 passed
  • PLAYWRIGHT_PROJECT=pages-router pnpm test:e2e — 85/85 passed, no regressions

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/594 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 3/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `opencode/quiet-nebula` --- ### 📝 Commits (5) - [`8b4ab93`](https://github.com/cloudflare/vinext/commit/8b4ab93e901abf1df19311478ec1a6dbbf11ad48) feat: implement next/document with class-based Document and getInitialProps support - [`422b602`](https://github.com/cloudflare/vinext/commit/422b60238ed4db44595e890943cf2b80e71d6da8) fix: address review comments on next/document getInitialProps - [`38c4587`](https://github.com/cloudflare/vinext/commit/38c458708f99181d1294de86adeedc9feef7c47b) feat(pages-router): render error pages through custom _document with getInitialProps - [`d9509c4`](https://github.com/cloudflare/vinext/commit/d9509c4d8125f592a4aaf37e237ce428d2f2c60a) feat(pages-router): implement App.getInitialProps and fix appProps propagation - [`6cd668e`](https://github.com/cloudflare/vinext/commit/6cd668e0f76c15003dd6395c4045a12230959a7f) fix(pages-router): inject client entry script and fix asset preloading ### 📊 Changes **18 files changed** (+1050 additions, -129 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/client/entry.ts` (+7 -3) 📝 `packages/vinext/src/entries/pages-client-entry.ts` (+2 -2) 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+194 -16) 📝 `packages/vinext/src/index.ts` (+1 -1) 📝 `packages/vinext/src/server/dev-server.ts` (+181 -12) 📝 `packages/vinext/src/server/middleware.ts` (+21 -36) 📝 `packages/vinext/src/server/prod-server.ts` (+20 -0) 📝 `packages/vinext/src/shims/app.ts` (+68 -4) 📝 `packages/vinext/src/shims/document.tsx` (+61 -11) 📝 `packages/vinext/src/shims/next-shims.d.ts` (+86 -0) 📝 `packages/vinext/src/shims/router.ts` (+5 -1) 📝 `playwright.config.ts` (+3 -1) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+196 -18) ➕ `tests/e2e/pages-router-prod/document.spec.ts` (+47 -0) ➕ `tests/e2e/pages-router/document.spec.ts` (+48 -0) 📝 `tests/fixtures/pages-basic/next-shims.d.ts` (+74 -7) 📝 `tests/fixtures/pages-basic/pages/_app.tsx` (+7 -3) 📝 `tests/fixtures/pages-basic/pages/_document.tsx` (+29 -14) </details> ### 📄 Description ## Summary - Rewrites the `next/document` shim to export proper TypeScript types (`DocumentContext`, `DocumentInitialProps`) and a class-based `Document` base class with a default `getInitialProps` static method - Adds ambient `declare module 'next/document'` types to `next-shims.d.ts` so custom `_document.tsx` files type-check correctly - Wires `getInitialProps` into the Pages Router dev server via a new `buildDocumentContext` helper — custom documents can now augment document props (e.g. injecting a theme) - Updates the test fixture `_document.tsx` to use a class-based document with `getInitialProps` that adds a `theme` prop rendered as `data-theme-prop` on `<body>` - Adds a new E2E test (`tests/e2e/pages-router/document.spec.ts`) that verifies the custom document prop is present in the rendered HTML ## Testing - `PLAYWRIGHT_PROJECT=pages-router pnpm test:e2e tests/e2e/pages-router/document.spec.ts` — 1 passed - `PLAYWRIGHT_PROJECT=pages-router pnpm test:e2e` — 85/85 passed, no regressions --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#695
No description provided.