cloudflare/vinext

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

已关闭

#1,329 创建于 2026年5月20日

 (3 条评论) (0 个反应) (0 位负责人)TypeScript (384 个派生)github user discovery
adapter-api-e2ehelp wanted

仓库指标

星标
 (8,625 个星标)
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.

贡献者指南