Pages Router: `window.next.router` global not exposed during hydration
#1,329 opened on May 20, 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-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
-
Reproduce first in vinext's own test suite. Before submitting a PR, add a test case in the relevant
tests/*.test.tsfile that verifieswindow.next.routeris exposed on Pages Router pages after hydration. Confirm it fails, then implement the fix. -
Study the Next.js implementation. Look at
packages/next/src/client/index.tsxin the Next.js source to understand what properties are set onwindow.nextand when. At minimum,window.next.routermust expose.pathname,.query,.push(),.replace(),.events, and other standard router properties. -
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. -
Verify dev/prod parity. Ensure the global is available in both development and production builds.