Skip to content

Commit

Permalink
fix unhandled runtime error when notFound() triggered in generateMeta…
Browse files Browse the repository at this point in the history
…data w/ parallel routes
  • Loading branch information
ztanner committed Apr 27, 2024
1 parent 5897fc0 commit 8b26dc1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
Expand Up @@ -443,7 +443,10 @@ async function createComponentTreeInternal({
injectedJS: injectedJSWithCurrentLayout,
injectedFontPreloadTags: injectedFontPreloadTagsWithCurrentLayout,
asNotFound,
metadataOutlet,
// The metadataOutlet is responsible for throwing any errors that were caught during metadata resolution.
// We only want to render an outlet once per segment, as otherwise the error will be triggered
// multiple times causing an uncaught error.
metadataOutlet: isChildrenRouteKey ? metadataOutlet : undefined,
ctx,
missingSlots,
})
Expand Down
@@ -0,0 +1,3 @@
export default function Page() {
return <div>@bar</div>
}
@@ -0,0 +1,9 @@
export function generateMetadata() {
return {
title: 'Create Next App',
}
}

export default function Page() {
return <div>@foo</div>
}
@@ -0,0 +1,12 @@
import { notFound } from 'next/navigation'

export function generateMetadata() {
notFound()
return {
title: 'Create Next App',
}
}

export default function Page() {
return <h1>Hello from Page</h1>
}
Expand Up @@ -57,6 +57,14 @@ describe('parallel-route-not-found', () => {
expect(warnings.length).toBe(0)
})

it('should handle `notFound()` in generateMetadata on a page that also renders a parallel route', async () => {
const browser = await next.browser('/not-found-metadata')

expect(await browser.elementByCss('body').text()).toMatch(
/This page could not be found/
)
})

if (isNextDev) {
it('should not log any warnings for a regular not found page', async () => {
const browser = await next.browser('/this-page-doesnt-exist')
Expand Down

0 comments on commit 8b26dc1

Please sign in to comment.