Skip to content

Commit

Permalink
Update parallel missing slot
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 9, 2023
1 parent 5e4303c commit ef0502b
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 77 deletions.
47 changes: 31 additions & 16 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,22 +364,37 @@ async function createTreeCodeFromPath(

for (const adjacentParallelSegment of adjacentParallelSegments) {
if (!props[normalizeParallelKey(adjacentParallelSegment)]) {
const actualSegment =
adjacentParallelSegment === 'children' ? '' : adjacentParallelSegment
const defaultPath =
(await resolver(
`${appDirPrefix}${segmentPath}/${actualSegment}/default`
)) ?? 'next/dist/client/components/parallel-route-default'

props[normalizeParallelKey(adjacentParallelSegment)] = `[
'__DEFAULT__',
{},
{
defaultPage: [() => import(/* webpackMode: "eager" */ ${JSON.stringify(
defaultPath
)}), ${JSON.stringify(defaultPath)}],
}
]`
const isChildrenRoute = adjacentParallelSegment === 'children'
const actualSegment = isChildrenRoute ? '' : adjacentParallelSegment

const normalizedKey = normalizeParallelKey(adjacentParallelSegment)
if (isChildrenRoute) {
const defaultPath =
'next/dist/client/components/parallel-route-default-not-found'
props[normalizedKey] = `[
'__DEFAULT__',
{},
{
defaultPage: [() => import(/* webpackMode: "eager" */ ${JSON.stringify(
defaultPath
)}), ${JSON.stringify(defaultPath)}],
}
]`
} else {
const defaultPath =
(await resolver(
`${appDirPrefix}${segmentPath}/${actualSegment}/default`
)) ?? 'next/dist/client/components/parallel-route-default-slot'
props[normalizedKey] = `[
'__DEFAULT__',
{},
{
defaultPage: [() => import(/* webpackMode: "eager" */ ${JSON.stringify(
defaultPath
)}), ${JSON.stringify(defaultPath)}],
}
]`
}
}
}
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { notFound } from './not-found'

export default function ParallelRouteDefaultNotFound() {
notFound()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function ParallelRouteDefaultSlot() {
return null
}

This file was deleted.

18 changes: 18 additions & 0 deletions test/e2e/app-dir/parallel-routes-missing-slot/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createNextDescribe } from 'e2e-utils'

createNextDescribe(
'app dir - parallel routes missing slot',
{
files: __dirname,
skipDeployment: true,
},
({ next }) => {
it('should only render the children slot when the custom slot is missing', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('body').text()).toBe(
'@children rendered'
)
expect(await browser.hasElementByCssSelector('#children-slot')).toBe(true)
})
}
)
8 changes: 0 additions & 8 deletions test/e2e/app-dir/parallel-routes-not-found/next.config.js

This file was deleted.

This file was deleted.

24 changes: 0 additions & 24 deletions test/e2e/app-dir/parallel-routes-not-found/tsconfig.json

This file was deleted.

0 comments on commit ef0502b

Please sign in to comment.