Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix unhandled runtime error when notFound() triggered in generateMeta…
…data w/ parallel routes (#65102) ### What When a page throws a `notFound()` error in `generateMetadata`, and the page contains parallel route(s), an unhandled runtime error would be thrown rather than displaying the not found page. ### Why We use the `<MetadataOutlet />` component to throw any errors caught during metadata resolution once the metadata is rendered by React so that it can be caught by an error boundary, so that it doesn't throw during metadata resolution. A promise is tracked & resolved with an error once the metadata tree is rendered. Once the promise resolves, the outlet component will throw. However, every `__PAGE__` segment that would be rendered as part of the page the user is on will render this `<MetadataOutlet />` component. We only need a single outlet per segment as only a single error needs to be thrown & caught. ### How This will only render a `MetadataOutlet` for the first parallel route that is encountered at each segment depth, as we only need a single handler to throw the error. Fixes #65013 Closes NEXT-3222
- Loading branch information
Showing
14 changed files
with
104 additions
and
5 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
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-route-not-found/app/@bar/not-found-metadata/no-page/page.tsx
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 <div>@bar slot</div> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-route-not-found/app/@bar/not-found-metadata/page-error/page.tsx
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 <div>@bar slot</div> | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/parallel-route-not-found/app/@bar/not-found-metadata/slot-error/page.tsx
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,9 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
export function generateMetadata() { | ||
notFound() | ||
} | ||
|
||
export default function Page() { | ||
return <div>@bar slot</div> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-route-not-found/app/@foo/not-found-metadata/no-page/page.tsx
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 <div>@foo slot</div> | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/parallel-route-not-found/app/@foo/not-found-metadata/page-error/page.tsx
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,9 @@ | ||
export function generateMetadata() { | ||
return { | ||
title: 'Create Next App', | ||
} | ||
} | ||
|
||
export default function Page() { | ||
return <div>@foo slot</div> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-route-not-found/app/@foo/not-found-metadata/slot-error/page.tsx
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 <div>@foo slot</div> | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/parallel-route-not-found/app/not-found-metadata/no-page/@foobar/page.tsx
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,9 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
export function generateMetadata() { | ||
notFound() | ||
} | ||
|
||
export default function Page() { | ||
return <div>@foobar slot</div> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-route-not-found/app/not-found-metadata/no-page/layout.tsx
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 Layout(props: { foobar: React.ReactNode }) { | ||
return <>{props.foobar}</> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-route-not-found/app/not-found-metadata/not-found.tsx
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 <div>Custom Not Found!</div> | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/parallel-route-not-found/app/not-found-metadata/page-error/page.tsx
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,9 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
export function generateMetadata() { | ||
notFound() | ||
} | ||
|
||
export default function Page() { | ||
return <h1>Hello from Page</h1> | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/parallel-route-not-found/app/not-found-metadata/slot-error/page.tsx
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,9 @@ | ||
export function generateMetadata() { | ||
return { | ||
title: 'Create Next App', | ||
} | ||
} | ||
|
||
export default function Page() { | ||
return <h1>Hello from Page</h1> | ||
} |
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