tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
571 stars 23 forks source link

Strategy for evaluating page files or reading their AST #138

Open tatethurston opened 1 year ago

tatethurston commented 1 year ago

Next's documentation notes the following:

During prerendering, the router's query object will be empty since we do not have query information to provide during this phase. After hydration, Next.js will trigger an update to your application to provide the route parameters in the query object.

To ensure type safety, nextjs-routes assumes every page is optimized. This requires that clients always use router.isReady to narrow the router.query type when using useRouter.

If we import/require the transpiled page files (or read the AST), we can detect whether a page will be optimized. This will also unblock https://github.com/tatethurston/nextjs-routes/issues/132 and possibly https://github.com/tatethurston/nextjs-routes/issues/39.

A few considerations:

There will be some tradeoffs here wrt complexity, we may need to investigate a few different solutions to minimize the amount of complexity this package takes on.