Skip to content

Commit

Permalink
fix unnecessary missing slots warnings (vercel#74677)
Browse files Browse the repository at this point in the history
This is meant to provide a warning when a `notFound` page is triggered
by an unmatched parallel route, but was erroneously triggering for
deliberate `notFound()` cases as well. This adjusts the warning to only
occur when `missingSlots` has items in the set which will only be the
case when a missing non-children slot triggers the `notFound()`

Fixes vercel#74642
  • Loading branch information
ztanner authored Jan 9, 2025
1 parent d79f21c commit 783ec47
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,20 @@ class HTTPAccessFallbackErrorBoundary extends React.Component<
if (
process.env.NODE_ENV === 'development' &&
this.props.missingSlots &&
this.props.missingSlots.size > 0 &&
// A missing children slot is the typical not-found case, so no need to warn
!this.props.missingSlots.has('children')
) {
let warningMessage =
'No default component was found for a parallel route rendered on this page. Falling back to nearest NotFound boundary.\n' +
'Learn more: https://nextjs.org/docs/app/building-your-application/routing/parallel-routes#defaultjs\n\n'

if (this.props.missingSlots.size > 0) {
const formattedSlots = Array.from(this.props.missingSlots)
.sort((a, b) => a.localeCompare(b))
.map((slot) => `@${slot}`)
.join(', ')
const formattedSlots = Array.from(this.props.missingSlots)
.sort((a, b) => a.localeCompare(b))
.map((slot) => `@${slot}`)
.join(', ')

warningMessage += 'Missing slots: ' + formattedSlots
}
warningMessage += 'Missing slots: ' + formattedSlots

warnOnce(warningMessage)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <div>@bar slot</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <div>@bar slot</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { notFound } from 'next/navigation'

export default function NotFoundError() {
notFound()
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ describe('parallel-route-not-found', () => {
}
})

it('should not include any parallel route warnings for a deliberate notFound()', async () => {
const browser = await next.browser('/has-both-slots/not-found-error')
const logs = await browser.log()

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

const warnings = logs.filter((log) => log.source === 'warning')
expect(warnings.length).toBe(0)
})

it('should render the page & slots if all parallel routes are found', async () => {
const browser = await next.browser('/has-both-slots')
const logs = await browser.log()
Expand Down

0 comments on commit 783ec47

Please sign in to comment.