-
Notifications
You must be signed in to change notification settings - Fork 26k
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 + notFound is not working #38239
Comments
Is there any solution or workaround yet? We use NextJS in connection with TinaCMS. We download the content from a database and the page json is compiled into a page with next build && next export. What I also noticed is, that when I compile my projects with node 16, everything seems to work. |
Same problem here. When I put the middleware.js file, 404 not work properly and try to enter on the page. If I put just an clean middleware file, Link component doesn't work properly. |
Well I now had the time to upgrade to Node 16, but it didn't work either. It looks like when i export or build the project, the problem seems to come up ^^' |
I guess they did great job by ruining the old system by replacing legacy |
Yeah.....well actually it helps downgrading to 12.1.6 ^^' |
Had the same issue with |
I'll give it a try if it's resolved I'll close this issue. |
Any update on this issue? |
Closing as this does appear to be working as expected in the latest version of Next.js |
@ijjk The issue is present in the latest version, please reopen it. My use-case specifically is One more detail - works fine when navigating directly to 404 link, but is broken when using client-side navigation via |
I can confirm that this issue is still exists on the latest next (v13.1.1). I use If I open exisiting page like If I open 404 page directlry (I see 404 error page) and then open another 404 page like If I open some other page (not If I run |
@ijjk Any update here? It still appears to be broken. |
#43953 - same |
Any updates? |
@ijjk this keeps happening on |
Can confirm that this is also occurring for me on 13.1.6. |
I'm not able to check this with |
Hi, @emmgfx , |
In checking some other behaviour (#46613) I also stumbled upon this. I've got an example with current 13.2.3 version. On dev I notice that the first click it seems to ignore the But more strange (and concerning to me) is that on production, going to the link will just render Repo: https://github.com/joggienl/nextjs-middleware-and-redirects Direct link to the page with |
This ensures we properly handle rendering the `404` page when `notFound: true` is returned and middleware is present. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) Fixes: #38239 x-ref: #43772 --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Hi, this has been updated in |
Cool! I've updated the example I added to this thread. I do get a strange response on Vercel though: https://nextjs-middleware-and-redirects.vercel.app/de/post/2 I am not sure if it is related, I also do not have a clear reproduction path. Any thoughs @ijjk ? edit: "no clear reproduction", it only happens on Vercel when navigating directly to that page (or a refresh). Navigation via on page links works as expected. Also I could not "break" it locally both dev and build-start. |
@joggienl Thanks for sharing, was able to reproduce that myself too—we'll take a look! |
Ensures we properly generate the 404 page when a path is being prefetched with middleware configured. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) Closes: #38239 (comment)
Hey @samcx , just tested 13.2.4-canary.4. It seems to be fixed, thanks! |
@hafizasadabbas There was an additional fix on one canary version above the one you tested. Can you test the latest canary and see if the issue persists? |
@samcx Still not working with 13.2.4-canary.4. import { NextResponse } from "next/server"; export function middleware() { No issue on dev but on vercel preview URL. Also, the issue only appears when I land on a dynamic URL through the Next link, and when I reload the page appears. I have noticed 1 more thing in the network tab the request URL looks like When I delete middleware.js the request URL becomes |
@hafizasadabbas can you provide the actual deployment? Looks like the one you shared is deleted. Also we have tests covering this specific handling with |
@hafizasadabbas Is it possible to create a public, minimal reproduction repository that showcases this page+issue so we can take a closer look? |
I can confirm that issue described by me above was fixed in |
hello i having this issue when try to use dynamic import i try v13.2.4 and latest and does not work/* eslint @typescript-eslint/no-var-requires: "off" / /* eslint @typescript-eslint/no-unused-vars: "off" */ /* eslint-disable etc/no-commented-out-code / import type { import dynamic from 'next/dynamic'; import { useAccount } from 'wagmi' const PangolinProvider = dynamic( const SwapWidget = dynamic(() => import('@pangolindex/components').then((module) => module.SwapWidget) as any, { export default function Swap() { const useStyles = makeStyles((theme :any)=> ({ useEffect(()=>{ const { address } = useAccount() const classes = useStyles();
<Typography fontFamily={"poppins"} color="white" variant="h1" component="h1" className={classes.title}>
) |
I am on next@13.3.0 and still facing the issue. |
I am on next@13.3.1 and have the same issue: middleware + getServerSideProps + Vercel => 404. But it works in the dev local. |
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
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 14.19.1
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.2.0
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When using middleware and navigate to a page using
next/link
that return in it'sgetStaticProps
a{ notFound:true }
the middleware returns the page itself instead of 404.Expected Behavior
When the page returns
{ notFound: true }
the middleware should return 404 page.Link to reproduction
https://github.com/Louai99k/next-not-found-bug
To Reproduce
Just install the repo above and run it on your machine. You'll notice in the main page 2 links one normal anchor tag and a
next/link
. if the middleware exist the link comp from next won't work while the a tag will be working but after removing the middleware both of the links will work just fine.Not: the api end point returns 404 response and that's my condition in the project to return 404 page.
The text was updated successfully, but these errors were encountered: