-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Handle 404 page when getStaticProps.notFound = true or the route is not found #3448
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
8 Ignored Deployments
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
9d0c5fa
to
2f70ae4
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.
Isn't it better to respond with Rewrite("/404")
instead of compiling the error and 404 page into every page?
984eda7
to
2596995
Compare
2f70ae4
to
75853c5
Compare
2596995
to
ebcca97
Compare
9cf1ac7
to
f894b2f
Compare
f894b2f
to
b06ef20
Compare
b06ef20
to
80ed2b5
Compare
@@ -188,6 +169,19 @@ export default function startHandler({ | |||
headers: renderData.headers, | |||
} as any; | |||
const res: ServerResponse = new ServerResponseShim(req) as any; | |||
|
|||
// Both _error and 404 should receive a 404 status code. |
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.
Could you explain why _error
isn't 500?
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.
When navigating to /_error
in Next.js, a 404 status is always returned.
Benchmark for 3ca3704Click to view benchmark
|
|
f685cf8
to
d3b412b
Compare
Benchmark for 40e1f7bClick to view benchmark
|
d3b412b
to
8490a5d
Compare
Benchmark for 6702ba9
Click to view full benchmark
|
Merging this as the only CI failure is unrelated to this PR. |
The new error paths introduced in #3448 both write their outputs to `.next/server/pages/`, which conflicts with: - The main pages source - Each other The infinite loop is very fun: 1. We need a `NodeJsPoolVc` to render pages 2. To get a `NodeJsPoolVc`, you need to write your files onto disk - So a pool is dependent on the contents of those files 3. When we render an error page, we need to write those files to disk 4. The error page shares the same file entrypoint as the main page source So, to render an error, we write the entrypoint, which is shared with main source. This alone is pretty bad, because it will invalidate our page source's node pool (and kill those processes). But, the loop is triggered by a more subtle bug: When we write a file, we read it to see if the contents have changed. Writing creates a dependency on the read! So when the error page is written to disk, it invalidated the read we preformed when we wrote the main page. That invalidated the main page (and it's node pool), and so we rendered again. That wrote the main page's code to disk, invalidating the read of the error page performed when we wrote the error page. ♾️ (I'll be opening more PRs…)
…ot found (vercel/turbo#3448) This specifically supports the case where `getStaticProps.notFound = true` or a matching route is not found, but not the case where `getStaticPaths.fallback = false` and the route is not enumerated; This separate case will be implemented in another PR.
The new error paths introduced in vercel/turbo#3448 both write their outputs to `.next/server/pages/`, which conflicts with: - The main pages source - Each other The infinite loop is very fun: 1. We need a `NodeJsPoolVc` to render pages 2. To get a `NodeJsPoolVc`, you need to write your files onto disk - So a pool is dependent on the contents of those files 3. When we render an error page, we need to write those files to disk 4. The error page shares the same file entrypoint as the main page source So, to render an error, we write the entrypoint, which is shared with main source. This alone is pretty bad, because it will invalidate our page source's node pool (and kill those processes). But, the loop is triggered by a more subtle bug: When we write a file, we read it to see if the contents have changed. Writing creates a dependency on the read! So when the error page is written to disk, it invalidated the read we preformed when we wrote the main page. That invalidated the main page (and it's node pool), and so we rendered again. That wrote the main page's code to disk, invalidating the read of the error page performed when we wrote the error page. ♾️ (I'll be opening more PRs…)
…ot found (vercel/turbo#3448) This specifically supports the case where `getStaticProps.notFound = true` or a matching route is not found, but not the case where `getStaticPaths.fallback = false` and the route is not enumerated; This separate case will be implemented in another PR.
The new error paths introduced in vercel/turbo#3448 both write their outputs to `.next/server/pages/`, which conflicts with: - The main pages source - Each other The infinite loop is very fun: 1. We need a `NodeJsPoolVc` to render pages 2. To get a `NodeJsPoolVc`, you need to write your files onto disk - So a pool is dependent on the contents of those files 3. When we render an error page, we need to write those files to disk 4. The error page shares the same file entrypoint as the main page source So, to render an error, we write the entrypoint, which is shared with main source. This alone is pretty bad, because it will invalidate our page source's node pool (and kill those processes). But, the loop is triggered by a more subtle bug: When we write a file, we read it to see if the contents have changed. Writing creates a dependency on the read! So when the error page is written to disk, it invalidated the read we preformed when we wrote the main page. That invalidated the main page (and it's node pool), and so we rendered again. That wrote the main page's code to disk, invalidating the read of the error page performed when we wrote the error page. ♾️ (I'll be opening more PRs…)
import Error, { getStaticProps } from "@vercel/turbopack-next/internal/_error"; | ||
|
||
export default Error; | ||
export { getStaticProps }; |
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.
this is actually not supported by next.js
https://nextjs.org/docs/advanced-features/custom-error-page#caveats
This specifically supports the case where
getStaticProps.notFound = true
or a matching route is not found, but not the case wheregetStaticPaths.fallback = false
and the route is not enumerated;This separate case will be implemented in another PR.