-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Deprecate page
parameter for Middleware
#34521
Comments
The rest of your comment about I've noted anecdotally that |
That's good to know @tavvy as it confirms that this feature is not as useful as initially expected. What I mean referring to We can also add a snippet for a helper in the error link to actually make it worth with the exact Next.js page route like |
Thanks @javivelasco and I can see both the problem and the solution you are proposing now. Perhaps our use case is a little unique so let me explain as it may be a valid use case of the feature; We use We would like a "global" root level middleware to handle session setting. But we only want to do this for the Next.js handled pages, when we rewrite to the legacy system it performs its own session handling that we do not want to clash with. The easiest and most intuitive way to achieve this was to stick an "early exit" handler at the top of the middleware. if (!request.page.name) return NextResponse.next();
// ... session setting logic Im sure there are different variations on this usage. Basically it is useful to have some kind of indicator that the page is a known route to the Next.js app. Hence my question about how I might access the page manifest from within the middleware to construct my own You could just scope your What if you do the inverse and match on a known fallback route? |
Should issues that are specific to Vercel deployment rather than Next be reported here? My Vercel issue: vercel/vercel#7452 |
I've realised that Next itself needs to know which page will be matched in middleware. Given folder structure like this:
When a user requests /page My suggestion would be to keep |
Related: #29750 (comment) |
It uses `URLSearchParams` to have the same behavior. closes #34521
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Currently, in Middleware,
NextRequest
holds apage
property that can be used to foresee if the incoming request will match a page or not. This feature is intended to help users detect if a certain page will be render and, in the case of dynamic routes, which ones are the parameters that they will be matching.This information is based on simply checking if there is a static/dynamic page route that matches the request. The problem is that when the request matches a static file, it will still check if there is a page match and it is not possible to detect if there is a static file that matches at that specific stage.
This feature can be replaced by using path-to-regexp or any other library or regexp and it is adding logic to the middleware bundle that many users may not need, growing its size when there is no need to.
We should entirely remove the feature so that when
request.page
is accessed we can fail with an error and a link that provides a code snippet with an alternative to the feature.The text was updated successfully, but these errors were encountered: