Skip to content

Commit

Permalink
Merge branch 'canary' into wyattjoh/create-next-app-head
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh authored Nov 2, 2022
2 parents e15b2ad + b69dac1 commit fada204
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/next/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const FILE_TYPES = {
'not-found': 'not-found',
} as const

const PAGE_SEGMENT = 'page$'

// TODO-APP: check if this can be narrowed.
type ComponentModule = () => any
export type ComponentsType = {
Expand Down Expand Up @@ -59,10 +61,8 @@ async function createTreeCodeFromPath({
}

for (const [parallelKey, parallelSegment] of parallelSegments) {
const parallelSegmentPath = segmentPath + '/' + parallelSegment

if (parallelSegment === 'page') {
const matchedPagePath = `${appDirPrefix}${parallelSegmentPath}`
if (parallelSegment === PAGE_SEGMENT) {
const matchedPagePath = `${appDirPrefix}${segmentPath}/page`
const resolvedPagePath = await resolve(matchedPagePath)
if (resolvedPagePath) pages.push(resolvedPagePath)

Expand All @@ -73,6 +73,7 @@ async function createTreeCodeFromPath({
continue
}

const parallelSegmentPath = segmentPath + '/' + parallelSegment
const subtree = await createSubtreePropsFromSegmentPath([
...segments,
parallelSegment,
Expand Down Expand Up @@ -175,12 +176,18 @@ const nextAppLoader: webpack.LoaderDefinitionFunction<{
const matched: Record<string, string> = {}
for (const path of normalizedAppPaths) {
if (path.startsWith(pathname + '/')) {
const restPath = path.slice(pathname.length + 1)
const rest = path.slice(pathname.length + 1).split('/')

let matchedSegment = rest[0]
// It is the actual page, mark it sepcially.
if (rest.length === 1 && matchedSegment === 'page') {
matchedSegment = PAGE_SEGMENT
}

const matchedSegment = restPath.split('/')[0]
const matchedKey = matchedSegment.startsWith('@')
? matchedSegment.slice(1)
: 'children'

matched[matchedKey] = matchedSegment
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/app-dir/app/app/dashboard/page/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function DashboardPagePage() {
return (
<>
<p>hello dashboard/page!</p>
</>
)
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ describe('app dir', () => {
)
})

it('should serve page as a segment name correctly', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/page')
expect(html).toContain('hello dashboard/page!')
})

it('should include document html and body', async () => {
const html = await renderViaHTTP(next.url, '/dashboard')
const $ = cheerio.load(html)
Expand Down

0 comments on commit fada204

Please sign in to comment.