Closed BorghildSelle closed 1 month ago
Thanks for the report, it looks similar to #591, but in both cases I haven't been able to reproduce it with a stock Next.js app, maybe there is something else in your setup that causes this?
Reproduction: https://github.com/franky47/nuqs-repro-640
Hmm, we are using pages router with getServerSideProps and Per-page layout: https://nextjs.org/docs/pages/building-your-application/routing/pages-and-layouts#per-page-layouts Dont know what other could cause this since we are using next/router many other places.
In the browser the error displays like this as when it renders on the server:
Server Error
Error: invariant expected app router to be mounted
Could it be that your getLayout
function is called outside of a page render lifecycle? That could be an explanation as why the router is not available to nuqs hooks, if they are defined in the layout tree.
Maybe related to output singleton as we can import an singletonrouter, which then gives an router when i
import singletonRouter from 'next/router'
...
useEffect(() => {
if (singletonRouter) {
console.log(singletonRouter)
}
}, [singletonRouter])
When i just use router = useRouter() is says:
NextRouter was not mounted.
We didnt get the error when conditionally render the react component with nuqs with !isServerRendered
Did you get any further? Feel free to reopen with a reproduction repository if the issue still occurs.
Context
What's your version of
nuqs
?Next.js information (obtained by running
next info
):Are you using:
basePath
option in your Next.js configwindowHistorySupport
flag in your Next.js configDescription
When setting up nuqs like this on an SSR page in Next with Pages router:
we get this error:
We are using useRouter from next/router multiple places without error. We have not started migration to app yet, so no /app folder. This error appeared when installing nuqs. What could be wrong?
Reproduction
Use Nuqs with Nextjs 13.5.6 Pages router on a SSR page