Skip to content
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

Merged
merged 3 commits into from Jan 27, 2023

Conversation

alexkirsz
Copy link
Contributor

@alexkirsz alexkirsz commented Jan 24, 2023

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.

@alexkirsz alexkirsz requested a review from a team as a code owner January 24, 2023 10:42
@vercel
Copy link

vercel bot commented Jan 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
examples-cra-web 🔄 Building (Inspect) Jan 27, 2023 at 9:22AM (UTC)
examples-svelte-web 🔄 Building (Inspect) Jan 27, 2023 at 9:22AM (UTC)
8 Ignored Deployments
Name Status Preview Comments Updated
examples-basic-web ⬜️ Ignored (Inspect) Jan 27, 2023 at 9:22AM (UTC)
examples-designsystem-docs ⬜️ Ignored (Inspect) Jan 27, 2023 at 9:22AM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Jan 27, 2023 at 9:22AM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Jan 27, 2023 at 9:22AM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Jan 27, 2023 at 9:22AM (UTC)
examples-tailwind-web ⬜️ Ignored (Inspect) Jan 27, 2023 at 9:22AM (UTC)
examples-vite-web ⬜️ Ignored (Inspect) Jan 27, 2023 at 9:22AM (UTC)
turbo-site ⬜️ Ignored (Inspect) Visit Preview Jan 27, 2023 at 9:22AM (UTC)

@alexkirsz
Copy link
Contributor Author

alexkirsz commented Jan 24, 2023

@alexkirsz alexkirsz force-pushed the alexkirsz/web-448-handle-404-pages branch 4 times, most recently from 9d0c5fa to 2f70ae4 Compare January 24, 2023 11:14
Copy link
Member

@sokra sokra left a 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?

@alexkirsz alexkirsz force-pushed the alexkirsz/web-452-data-requests-for-dynamic-routes-are branch from 984eda7 to 2596995 Compare January 24, 2023 15:51
@alexkirsz alexkirsz requested a review from a team as a code owner January 24, 2023 15:51
@alexkirsz alexkirsz requested review from chris-olszewski and NicholasLYang and removed request for a team January 24, 2023 15:51
@alexkirsz alexkirsz force-pushed the alexkirsz/web-448-handle-404-pages branch from 2f70ae4 to 75853c5 Compare January 24, 2023 15:51
@alexkirsz alexkirsz force-pushed the alexkirsz/web-452-data-requests-for-dynamic-routes-are branch from 2596995 to ebcca97 Compare January 24, 2023 16:04
@alexkirsz alexkirsz force-pushed the alexkirsz/web-448-handle-404-pages branch 2 times, most recently from 9cf1ac7 to f894b2f Compare January 24, 2023 16:36
Base automatically changed from alexkirsz/web-452-data-requests-for-dynamic-routes-are to main January 24, 2023 18:30
@chris-olszewski chris-olszewski removed their request for review January 25, 2023 17:33
@sokra sokra self-requested a review January 25, 2023 18:26
@alexkirsz alexkirsz force-pushed the alexkirsz/web-448-handle-404-pages branch from f894b2f to b06ef20 Compare January 26, 2023 13:52
@alexkirsz alexkirsz force-pushed the alexkirsz/web-448-handle-404-pages branch from b06ef20 to 80ed2b5 Compare January 26, 2023 13:58
@alexkirsz alexkirsz changed the title Handle 404 page when getStaticProps.notFound = true Handle 404 page when getStaticProps.notFound = true or the route is not found Jan 26, 2023
@@ -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.
Copy link
Member

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?

Copy link
Contributor Author

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.

@github-actions
Copy link
Contributor

Benchmark for 3ca3704

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 7429.09µs ± 55.24µs 7497.64µs ± 52.79µs +0.92%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8024.04µs ± 202.73µs 7854.89µs ± 54.41µs -2.11%
bench_hmr_to_commit/Turbopack RSC/1000 modules 434.64ms ± 2.38ms 431.41ms ± 2.49ms -0.74%
bench_hmr_to_commit/Turbopack SSR/1000 modules 7645.33µs ± 71.12µs 7727.40µs ± 39.01µs +1.07%
bench_hmr_to_eval/Turbopack CSR/1000 modules 6515.58µs ± 54.92µs 6578.93µs ± 46.35µs +0.97%
bench_hmr_to_eval/Turbopack RCC/1000 modules 6877.63µs ± 46.67µs 6839.01µs ± 49.89µs -0.56%
bench_hmr_to_eval/Turbopack SSR/1000 modules 6853.25µs ± 61.59µs 6822.49µs ± 51.54µs -0.45%
bench_hydration/Turbopack RCC/1000 modules 3086.54ms ± 8.77ms 3081.80ms ± 6.55ms -0.15%
bench_hydration/Turbopack RSC/1000 modules 2689.89ms ± 10.17ms 2686.61ms ± 6.72ms -0.12%
bench_hydration/Turbopack SSR/1000 modules 2528.49ms ± 14.94ms 2526.90ms ± 5.13ms -0.06%
bench_startup/Turbopack CSR/1000 modules 1574.39ms ± 3.64ms 1568.85ms ± 3.74ms -0.35%
bench_startup/Turbopack RCC/1000 modules 2085.49ms ± 5.13ms 2075.19ms ± 5.15ms -0.49%
bench_startup/Turbopack RSC/1000 modules 1988.58ms ± 5.77ms 1990.44ms ± 5.02ms +0.09%
bench_startup/Turbopack SSR/1000 modules 1688.06ms ± 3.73ms 1677.67ms ± 6.18ms -0.62%

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2023

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Node.js lints

See workflow summary for details

@alexkirsz alexkirsz force-pushed the alexkirsz/web-448-handle-404-pages branch from f685cf8 to d3b412b Compare January 26, 2023 16:45
@alexkirsz alexkirsz added the pr: automerge Kodiak will merge these automatically after checks pass label Jan 26, 2023
@github-actions
Copy link
Contributor

Benchmark for 40e1f7b

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8335.28µs ± 50.81µs 8360.00µs ± 37.88µs +0.30%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8735.63µs ± 55.65µs 8682.08µs ± 68.42µs -0.61%
bench_hmr_to_commit/Turbopack RSC/1000 modules 447.94ms ± 2.16ms 448.53ms ± 2.13ms +0.13%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8462.10µs ± 52.84µs 8408.95µs ± 42.93µs -0.63%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7404.76µs ± 45.68µs 7436.45µs ± 45.62µs +0.43%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7591.03µs ± 70.93µs 7642.32µs ± 60.36µs +0.68%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7449.57µs ± 67.34µs 7530.47µs ± 41.54µs +1.09%
bench_hydration/Turbopack RCC/1000 modules 3140.31ms ± 9.33ms 3132.95ms ± 6.80ms -0.23%
bench_hydration/Turbopack RSC/1000 modules 2753.79ms ± 7.10ms 2737.21ms ± 6.86ms -0.60%
bench_hydration/Turbopack SSR/1000 modules 2591.94ms ± 8.06ms 2572.53ms ± 5.85ms -0.75%
bench_startup/Turbopack CSR/1000 modules 1610.91ms ± 6.04ms 1595.36ms ± 4.69ms -0.97%
bench_startup/Turbopack RCC/1000 modules 2123.12ms ± 4.76ms 2138.30ms ± 5.31ms +0.71%
bench_startup/Turbopack RSC/1000 modules 2032.15ms ± 5.90ms 2024.85ms ± 6.82ms -0.36%
bench_startup/Turbopack SSR/1000 modules 1716.16ms ± 3.22ms 1712.95ms ± 5.39ms -0.19%

@alexkirsz alexkirsz force-pushed the alexkirsz/web-448-handle-404-pages branch from d3b412b to 8490a5d Compare January 27, 2023 09:21
@github-actions
Copy link
Contributor

Benchmark for 6702ba9

Test Base PR % Significant %
bench_hydration/Turbopack SSR/1000 modules 2974.60ms ± 8.64ms 2932.99ms ± 9.53ms -1.40% -0.18%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8702.69µs ± 99.46µs 8759.34µs ± 194.07µs +0.65%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8986.91µs ± 76.46µs 8931.47µs ± 88.71µs -0.62%
bench_hmr_to_commit/Turbopack RSC/1000 modules 460.68ms ± 2.33ms 468.17ms ± 2.92ms +1.63%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8875.36µs ± 98.28µs 8742.63µs ± 68.83µs -1.50%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7694.09µs ± 117.19µs 8082.18µs ± 99.65µs +5.04%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7829.92µs ± 38.11µs 7876.28µs ± 68.33µs +0.59%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7911.60µs ± 127.30µs 7880.70µs ± 132.19µs -0.39%
bench_hydration/Turbopack RCC/1000 modules 3584.49ms ± 7.99ms 3568.85ms ± 9.78ms -0.44%
bench_hydration/Turbopack RSC/1000 modules 3136.50ms ± 7.99ms 3135.98ms ± 11.99ms -0.02%
bench_hydration/Turbopack SSR/1000 modules 2974.60ms ± 8.64ms 2932.99ms ± 9.53ms -1.40% -0.18%
bench_startup/Turbopack CSR/1000 modules 2011.78ms ± 13.65ms 2006.39ms ± 10.69ms -0.27%
bench_startup/Turbopack RCC/1000 modules 2348.66ms ± 7.23ms 2354.05ms ± 6.34ms +0.23%
bench_startup/Turbopack RSC/1000 modules 2254.58ms ± 6.63ms 2263.12ms ± 8.27ms +0.38%
bench_startup/Turbopack SSR/1000 modules 1944.94ms ± 3.69ms 1953.91ms ± 4.62ms +0.46%

@alexkirsz
Copy link
Contributor Author

Merging this as the only CI failure is unrelated to this PR.

@alexkirsz alexkirsz merged commit 2ec0330 into main Jan 27, 2023
@alexkirsz alexkirsz deleted the alexkirsz/web-448-handle-404-pages branch January 27, 2023 13:38
sokra pushed a commit that referenced this pull request Jan 28, 2023
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…)
jridgewell pushed a commit to vercel/next.js that referenced this pull request Mar 10, 2023
…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.
jridgewell added a commit to vercel/next.js that referenced this pull request Mar 10, 2023
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…)
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
…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.
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
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 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: automerge Kodiak will merge these automatically after checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants