-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
propagate notFound errors past a segment's error boundary (#60567)
### What? Throwing a `notFound()` error inside of a segment that has an error boundary will cause it to be handled by the segment's error boundary rather than a parent not-found boundary. ### Why? We assume anything that hits an `ErrorBoundary` is an actual error, but this should not be the case when the caught error is one that is handled by Next.js. ### How? This checks if the caught error is one that is expected to be handled someplace else. Closes NEXT-2080 [slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1705003189392509?thread_ts=1704868742.169129&cid=C03S8ED1DKM)
- Loading branch information
Showing
9 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use client' | ||
export default function Error() { | ||
return <div>There was an error</div> | ||
} |
10 changes: 10 additions & 0 deletions
10
test/e2e/app-dir/not-found/basic/app/error-boundary/nested/[dynamic]/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { notFound } from 'next/navigation' | ||
import React from 'react' | ||
|
||
export default function Page({ params }) { | ||
if (params.dynamic === 'trigger-not-found') { | ||
notFound() | ||
} | ||
|
||
return <div>Hello World</div> | ||
} |
4 changes: 4 additions & 0 deletions
4
test/e2e/app-dir/not-found/basic/app/error-boundary/nested/nested-2/error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use client' | ||
export default function Error() { | ||
return <div>There was an error</div> | ||
} |
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/not-found/basic/app/error-boundary/nested/nested-2/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use client' | ||
import { notFound } from 'next/navigation' | ||
import React from 'react' | ||
export default function Page() { | ||
const [shouldError, setShouldError] = React.useState(false) | ||
if (shouldError) { | ||
notFound() | ||
} | ||
return ( | ||
<button | ||
onClick={() => { | ||
setShouldError(true) | ||
}} | ||
> | ||
Trigger Not Found | ||
</button> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/not-found/basic/app/error-boundary/nested/not-found.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <h1>Not Found (error-boundary/nested)</h1> | ||
} |
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/not-found/basic/app/error-boundary/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use client' | ||
import { notFound } from 'next/navigation' | ||
import React from 'react' | ||
export default function Page() { | ||
const [shouldError, setShouldError] = React.useState(false) | ||
if (shouldError) { | ||
notFound() | ||
} | ||
return ( | ||
<button | ||
onClick={() => { | ||
setShouldError(true) | ||
}} | ||
> | ||
Trigger Not Found | ||
</button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters