Skip to content

window.next.router is occasionally undefined #1526

Description

@heyBett

Context

What's your version of nuqs?

"nuqs": "^2.9.4"

What framework are you using?

  • ❌ Next.js (app router)
  • ✅ Next.js (pages router)
  • ❌ React SPA (no router)
  • ❌ Remix
  • ❌ React Router
  • ❌ Other (please specify)
perating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.5.0: Mon Apr 27 20:39:42 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6031
  Available memory (MB): 36864
  Available CPU cores: 14
Binaries:
  Node: 24.15.0
  npm: 11.12.1
  Yarn: 1.22.22
  pnpm: 11.1.3
Relevant Packages:
  next: 16.3.0 // Latest available version is detected (16.3.0).
  eslint-config-next: N/A
  react: 19.2.7
  react-dom: 19.2.7
  typescript: 7.0.2
Next.js Config:
  output: standalone

Description

While using nuqs with a Next.js 16.3.0 project on the Pages Router (only happened on a production build, not under next dev), I noticed that window.next.router was occasionally undefined, causing navigation/query updates to fail.

I couldn’t reproduce the issue in a fresh Next.js project, so there may be something specific about my application’s setup or the interaction with other libraries.

As a workaround, I patched nuqs to use the stable router singleton exported by next/router instead of reading window.next.router. This resolved the issue consistently in my project.

I opened #1525 with the same change so you can take a look and determine whether it’s an appropriate fix or if there’s a better approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    adapters/next/pagesUses the Next.js pages routerbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions