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
Middleware causes router to choose root server-rendered [...catchall] over more specific dynamic route only in production #39266
Comments
also seeing this issue, ping @javivelasco on this ^ |
hmmm it does solve it for me though that commit makes it seem like the opposite behaviour is desired? will comment on the PR #39370 asking for clarification |
Closing as this should be resolved in the latest version of Next.js |
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. |
Verify canary release
Provide environment information
I am using codesandbox with
12.2.4-canary.9
, I don't know whynext info
is reporting12.1.7-canary.46
- if that were correct, this example wouldn't run at all as I'm using top level middleware.sandbox@sse-sandbox-kfj5rr:/sandbox$ sandbox@sse-sandbox-kfj5rr:/sandbox$ npx --no-install next infonpx --no-install next info
warn - Latest canary version not detected, detected: "12.1.7-canary.46", newest: "12.2.4-canary.9".
Please try the latest canary version (
npm install next@canary
) to confirm the issue still exists before creating a new issue.Read more - https://nextjs.org/docs/messages/opening-an-issue
warn - Latest canary version not detected, detected: "12.1.7-canary.46", newest: "12.2.4-canary.9".
Please try the latest canary version (
npm install next@canary
) to confirm the issue still exists before creating a new issue.Read more - https://nextjs.org/docs/messages/opening-an-issue
What browser are you using? (if relevant)
How are you deploying your application? (if relevant)
Deployed to Vercel
Describe the Bug
Top level middleware appears to be breaking routing to routes with dynamic segments, in favour of a less specific root
[...catchall].tsx
that usesgetServerSideProps
.Given the following directory structure:
where all pages except
[...catchall].tsx
are simple components (no use ofgetServersideProps
orgetStaticProps
) similar to this:and a top level middleware that applies only to
/broken/:path*
when trying to access a route
broken/[userid]/edit
with middleware in front of it, NextJS is routing instead to the less specific[...catchall].tsx
, which usesgetServerSideProps
/broken/somevalue/edit
. This happens even if the[...catchall]
redirects.This does not happen if:
[catchall]
instead of[...catchall]
(i.e. you use a dynamic route segment, but not one that is a catch all)getServerSideProps
_middleware.ts
I have not tried:
Expected Behavior
Adding middleware in front of a dynamic route should not affect routing.
Link to reproduction
https://codesandbox.io/s/nextjs-12-2-middleware-catchall-issue-kfj5rr?file=/pages/index.tsx
To Reproduce
This bug ONLY appears after building. It does not happen when running
next dev
.// ✔️ [...catchall]
// ✔️ middleware
// ✔️ bug
// https://csb-kfj5rr-pjwuo58u8-winwardo.vercel.app/
// ✔️ [...catchall], but without getServerSideProps
// ✔️ middleware
// ❌ bug
// https://csb-kfj5rr-dl8707jrw-winwardo.vercel.app/
// ❌ [...catchall]
// ✔️ middleware
// ❌ bug
// https://csb-kfj5rr-l5obh31us-winwardo.vercel.app/
// ❌ [...catchall]
// ✔️ [query]
// ✔️ middleware
// bug
// https://csb-kfj5rr-pnre13we2-winwardo.vercel.app/
The text was updated successfully, but these errors were encountered: