cloudflare/vinext

Pages Router: `window.next.router` global not exposed during hydration

已關閉

#1,329 建立於 2026年5月20日

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

倉庫指標

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

Problem

vinext does not expose window.next = { router } during Pages Router client-side hydration. In Next.js, packages/next/src/client/index.tsx sets this global during hydration, and it is the only programmatic way to trigger imperative client-side navigation outside React components.

Every test that calls browser.eval('next.router.push(...)') or reads browser.eval('next.router.pathname') fails immediately with:

TypeError: Cannot read properties of undefined (reading 'router')

or:

ReferenceError: next is not defined

Because the navigation never fires, downstream assertions (waiting for page content, checking URLs, verifying router events, checking window.__SAME_PAGE) all time out.

Estimated Impact

~80 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/middleware-general/test/node-runtime.test.ts (34 failures)
  • test/e2e/middleware-general/test/index.test.ts (32 failures)
  • test/e2e/middleware-rewrites/test/index.test.ts (21 failures)
  • test/e2e/trailing-slashes/with-trailing-slash.test.ts (20 failures)
  • test/e2e/trailing-slashes/without-trailing-slash.test.ts (20 failures)
  • test/e2e/basepath/query-hash.test.ts (10 failures)
  • test/e2e/basepath/router-events.test.ts (4 failures)
  • test/e2e/use-router-with-rewrites/use-router-with-rewrites.test.ts (7 failures)
  • test/e2e/with-router/index.test.ts (3 failures)
  • test/e2e/ignore-invalid-popstateevent/*.test.ts (5 failures)

Recommendation

  1. Reproduce first in vinext's own test suite. Before submitting a PR, add a test case in the relevant tests/*.test.ts file that verifies window.next.router is exposed on Pages Router pages after hydration. Confirm it fails, then implement the fix.

  2. Study the Next.js implementation. Look at packages/next/src/client/index.tsx in the Next.js source to understand what properties are set on window.next and when. At minimum, window.next.router must expose .pathname, .query, .push(), .replace(), .events, and other standard router properties.

  3. Wire up the global in the Pages Router client entry. The vinext Pages Router client entry (or hydration code) needs to set window.next = { version, router } after the router is initialized, mirroring what Next.js does.

  4. Verify dev/prod parity. Ensure the global is available in both development and production builds.

貢獻者指南