`useRouter` returns null on the server when using "experimental-edge" runtime
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
Binaries:
Node: 16.16.0
npm: 8.14.0
Yarn: 1.22.17
pnpm: 7.9.5
Relevant packages:
next: 13.0.0
eslint-config-next: 12.3.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
useRouter
returns null on the server
Expected Behavior
useRouter
should return the router both on server and client
Link to reproduction
https://github.com/remorses/try-next-getserversideprops-edge
To Reproduce
next dev
# visit index page
# router will be null in server logs
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:6 (4 by maintainers)
Top Results From Across the Web
useRouter is null; router.isready does not seem to work with ...
I run your code which gave an error sadly: Unhandled Runtime Error Error: Cannot read properties of undefined (reading 'isReady') Router is ......
Read more >Blog - Next.js 13
Next.js 13 introduces layouts, React Server Components, and streaming in the app directory, as well as Turbopack, an improved image ...
Read more >Next.js, useRouter hook, and testing - w11i.me
During a test the value returned by the useRouter hook appears to be either null or undefined . How to work around this?...
Read more >next: Versions | Openbase
Convert with-cssed , with-csx , with-styled-jsx examples to TypeScript: #43018; feat(examples): use experimental edge runtime with grafbase: #42992.
Read more >next/router | Next.js
useRouter is a React Hook, meaning it cannot be used with classes. ... It will be an empty object during prerendering if the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I confirm it’s fixed in canary 🥳
@remorses can you try the latest next? it should be already fixed by #43302 and #43192. I tested your reproduction locally it works well.