-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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 nested Middleware in favor of root middleware #36772
Deprecate nested Middleware in favor of root middleware #36772
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
3abe43f
to
38f006b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me but @ijjk should review the routing parts of the server 👍
97351e3
to
56dc9e1
Compare
56dc9e1
to
107ae0e
Compare
getMiddlewareRegex(middleware, { | ||
catchAll: !isSSR, | ||
}) | ||
)(cleanedAs) | ||
}) | ||
|
||
if (!requiresPreflight) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the above code/checks all be removed in favor a single flag like process.env.__NEXT_HAS_ROOT_MIDDLEWARE
which is set via the webpack config here?
next.js/packages/next/build/webpack-config.ts
Line 1522 in c72d32d
'process.env.__NEXT_HAS_REWRITES': JSON.stringify(hasRewrites), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a quite big change already I'd love to do that in a follow-up PR if that's ok for you @ijjk WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can do that in a follow-up 👍
15dc442
to
ff8dfc6
Compare
Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com> Update errors/nested-middleware.md Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com> Update errors/nested-middleware.md Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com> Update errors/nested-middleware.md Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com> Update errors/nested-middleware.md Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
b2fd604
to
a7bf05e
Compare
a7bf05e
to
a23dbe5
Compare
@javivelasco the filename not always starts with “middleware“. Actually, it starts with root directory. |
This PR deprecates declaring a middleware under
pages
in favour of the project root naming it aftermiddleware
instead of_middleware
. This is in the context of having a simpler execution model for middleware and also ships some refactor work. There is a ton of a code to be simplified after this deprecation but I think it is best to do it progressively.With this PR, when in development, we will fail whenever we find a nested middleware but we do not include it in the compiler so if the project is using it, it will no longer work. For production we will fail too so it will not be possible to build and deploy a deprecated middleware. The error points to a page that should also be reviewed as part of documentation.
Aside from the deprecation, this migrates all middleware tests to work with a single middleware. It also splits tests into multiple folders to make them easier to isolate and work with. Finally it ships some small code refactor and simplifications.