Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strategy for evaluating page files or reading their AST #138

Open
tatethurston opened this issue Apr 9, 2023 · 0 comments
Open

Strategy for evaluating page files or reading their AST #138

tatethurston opened this issue Apr 9, 2023 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@tatethurston
Copy link
Owner

tatethurston commented Apr 9, 2023

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 #132 and possibly #39.

A few considerations:

  • We may need to use the user's webpack configuration, to handle arbitrary ast extensions (JS/TS/JSX/TSX are examples). Those examples may be sufficient coverage, rather than supporting any possible ast extension.
  • In development, next lazily transpiles source files, so we may not have the full route picture. We shouldn't force evaluation of all page files, instead any code generation should likely become iterative. This will require updating the generated file via ast tooling rather than rewriting the whole file.

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.

@tatethurston tatethurston added enhancement New feature or request help wanted Extra attention is needed labels Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant