Skip to content

Commit

Permalink
Merge branch 'canary' into bump-pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 6, 2023
2 parents eb893c2 + f2f1c25 commit b8e8f7f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
15 changes: 5 additions & 10 deletions packages/next/src/lib/metadata/get-metadata-route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isMetadataRoute, isStaticMetadataRouteFile } from './is-metadata-route'
import { isMetadataRoute, isStaticMetadataRoute } from './is-metadata-route'
import path from '../../shared/lib/isomorphic/path'
import { interpolateDynamicPath } from '../../server/server-utils'
import { getNamedRouteRegex } from '../../shared/lib/router/utils/route-regex'
Expand Down Expand Up @@ -61,11 +61,11 @@ export function normalizeMetadataRoute(page: string) {
}
let route = page
let suffix = ''
if (route === '/robots') {
if (page === '/robots') {
route += '.txt'
} else if (route === '/manifest') {
} else if (page === '/manifest') {
route += '.webmanifest'
} else if (route.endsWith('/sitemap')) {
} else if (page.endsWith('/sitemap')) {
route += '.xml'
} else {
// Remove the file extension, e.g. /route-path/robots.txt -> /route-path
Expand All @@ -75,13 +75,8 @@ export function normalizeMetadataRoute(page: string) {
// Support both /<metadata-route.ext> and custom routes /<metadata-route>/route.ts.
// If it's a metadata file route, we need to append /[id]/route to the page.
if (!route.endsWith('/route')) {
const isStaticMetadataFile = isStaticMetadataRouteFile(page)
const { dir, name: baseName, ext } = path.parse(route)

const isStaticRoute =
page.startsWith('/robots') ||
page.startsWith('/manifest') ||
isStaticMetadataFile
const isStaticRoute = isStaticMetadataRoute(page)

route = path.posix.join(
dir,
Expand Down
8 changes: 8 additions & 0 deletions packages/next/src/lib/metadata/is-metadata-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export function isStaticMetadataRouteFile(appDirRelativePath: string) {
return isMetadataRouteFile(appDirRelativePath, [], true)
}

export function isStaticMetadataRoute(page: string) {
return (
page === '/robots' ||
page === '/manifest' ||
isStaticMetadataRouteFile(page)
)
}

/*
* Remove the 'app' prefix or '/route' suffix, only check the route name since they're only allowed in root app directory
* e.g.
Expand Down
8 changes: 3 additions & 5 deletions packages/next/src/server/dev/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ export function getEntryKey(
) {
// TODO: handle the /children slot better
// this is a quick hack to handle when children is provided as children/page instead of /page
return `${compilerType}@${pageBundleType}@${page.replace(
/(@[^/]+)\/children/g,
'$1'
)}`
const pageKey = page.replace(/(@[^/]+)\/children/g, '$1')
return `${compilerType}@${pageBundleType}@${pageKey}`
}

function getPageBundleType(pageBundlePath: string) {
Expand Down Expand Up @@ -521,7 +519,7 @@ export function onDemandEntryHandler({
let curInvalidator: Invalidator = getInvalidator(
multiCompiler.outputPath
) as any
let curEntries = getEntries(multiCompiler.outputPath) as any
const curEntries = getEntries(multiCompiler.outputPath) as any

if (!curInvalidator) {
curInvalidator = new Invalidator(multiCompiler)
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/server/lib/router-utils/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
ROUTES_MANIFEST,
} from '../../../shared/lib/constants'
import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep'
import { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route'

export type FsOutput = {
type:
Expand Down Expand Up @@ -578,11 +579,14 @@ export async function setupFsCheck(opts: {
}
}
} else if (type === 'pageFile' || type === 'appFile') {
const isAppFile = type === 'appFile'
if (
ensureFn &&
(await ensureFn({
type,
itemPath: curItemPath,
itemPath: isAppFile
? normalizeMetadataRoute(curItemPath)
: curItemPath,
})?.catch(() => 'ENSURE_FAILED')) === 'ENSURE_FAILED'
) {
continue
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/app-dir/metadata-dynamic-routes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ createNextDescribe(
isNextDev ? CACHE_HEADERS.NONE : CACHE_HEADERS.LONG
)

if (isNextDev) {
await check(async () => {
next.hasFile('.next/server/app-paths-manifest.json')
return 'success'
}, /success/)

const appPathsManifest = JSON.parse(
await next.readFile('.next/server/app-paths-manifest.json')
)
const entryKeys = Object.keys(appPathsManifest)
// Only has one route for twitter-image with catch-all routes in dev
expect(entryKeys).not.toContain('/twitter-image')
expect(entryKeys).toContain(
'/twitter-image/[[...__metadata_id__]]/route'
)
}

// edge runtime
res = await next.fetch('/twitter-image2')
expect(res.headers.get('content-type')).toBe('image/png')
Expand Down

0 comments on commit b8e8f7f

Please sign in to comment.