Breaking type change on useRouter()
in v13.0.2-canary.0
#42409
Labels
bug
Issue was opened via the bug report template.
useRouter()
in v13.0.2-canary.0
#42409
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
A breaking change seems to be introduced in #41767 now that
useRouter
returnsNextRouter | null
instead ofNextRouter
by default. Callingrouter.pathname
orrouter.events
, for instance, throws aType error: Object is possibly 'null'
error.Switching instances of
useRouter()
touseRouter(true)
was an easy enough fix, but I expect lots more people will be hitting this speed bump when this change is released.Expected Behavior
Is there a smart way to make this a non-breaking change? If this behavior is expected to be breaking, feel free to close this (but I'd still suggest emphasizing this change in the release notes to avoid a flood of bug reports! 😉)
Link to reproduction
vercel/examples#443 (review)
To Reproduce
Update from 13.0.1 to 13.0.2-canary.0 and up.
To fix with minimal changes, replace instances of
useRouter()
withuseRouter(true)
.Related: vercel/examples#443
The text was updated successfully, but these errors were encountered: