next.js: [NEXT-734] Revalidated page with notFound true does not return 404 Page
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
npx --no-install next info
Operating System:
Platform: linux
Arch: x64
Version: #32-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan 20 15:20:08 UTC 2023
Binaries:
Node: 16.19.0
npm: 8.19.3
Yarn: 1.22.19
pnpm: N/A
Relevant packages:
next: 13.2.2-canary.3
eslint-config-next: 13.2.1
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
https://github.com/floreq/200-to-404
To Reproduce
- Install project:
npm install
- Build and run production application:
npm run build && npm run start
- Go to
http://localhost:3000/blog/1
page. - Make some page refreshes.
- Spot that the page never become
404 Page
when minutes are even.- In this example, when minutes are even is set
notFound: true
for Post Page.
- In this example, when minutes are even is set
Describe the Bug
When a page was correctly generated. Than when getStaticProps
returns notFound: true
for that page. The page is not removed from .next/server/pages
. The page is still visible.
In the code to reproduce issue, when the page is revalidated with notFound: true
on even minutes. x-nextjs-cache
is set to STALE
and stays that way. Even if refreshing the page.
x-nextjs-cache
changes only toHIT
when the page is revalidated withoutnotFound: true
.
In next.config.js
is set isrMemoryCacheSize: 0
to highlight this problem.
//next.config.js
module.exports = {
[...]
experimental: {
isrMemoryCacheSize: 0,
},
};
Image 1
- correctly loaded page,
x-nextjs-cache: HIT
, odd minutes
Image 2
- incorrectly loaded page,
notFound: true
,x-nextjs-cache: STALE
, even minutes
Expected Behavior
When a page is successfully revalidated with notFound: true
returned from getStaticProps
:
- the page should display 404 Page, not itself,
- and the page should not be in
.next/server/pages
.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
next start
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 4
- Comments: 16 (2 by maintainers)
Yes, it’s the same issue but not related to using middleware.
Seems like the file is not removed from the file cache and so is still served despite being an invalid path now.
Only affected when using ISR Memory Cache = 0, for self-hosted solutions.
@samcx
Also be aware that while setting ISR cache to 0 is a fast track to triggering this issue, the issue becomes more devious when you realize that the default memory of 50MB can be exhausted by simply having a large site.
This happened to us. 2000 content pages in our CMS and suddenly deleted pages were popping back up and was extremely confusing and disruptive.
@samcx issue with was described by @ci-scott matches description from this thread. I think Link to the code that reproduces this issue will do.
Provided example:
notFound: true
.Yup, looks the same to me too.
I upgraded to v13.2.4, and still experiencing this issue @timneutkens . I don’t have a middleware in my project, setup is ± same as the one from OP.
duplicate or related to https://github.com/vercel/next.js/issues/38239?
I have a similar issue with notFound and getting
{}
as result of that page.Might as well past part of my comment here:
Repo: https://github.com/joggienl/nextjs-middleware-and-redirects Running “production” demo: https://nextjs-middleware-and-redirects.vercel.app/
Direct link to the page with getStaticProps and a notFound set for the specific id: https://nextjs-middleware-and-redirects.vercel.app/post/2