Skip to content

Commit

Permalink
revert changes to process default routes at build (vercel#61241)
Browse files Browse the repository at this point in the history
Reverts changes from vercel#61173 & vercel#60240 (while leaving the tests that were
added).

There are too many spots where considering `/default` routes as pages
needs to be carefully considered in different runtimes, and it turns out
that it's not actually needed to handle the case that it was originally
added for. I confirmed that the test that added the case it was intended
to fix (`parallel-routes-catchall-default`, along with the unit tests in
`normalize-catchall-routes`) are still passing as expected.
  • Loading branch information
ztanner authored Jan 27, 2024
1 parent b81ce72 commit 771e29c
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 32 deletions.
12 changes: 2 additions & 10 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ import {
isReservedPage,
isAppBuiltinNotFoundPage,
serializePageInfos,
isReservedAppPage,
} from './utils'
import type { PageInfo, PageInfos, AppConfig } from './utils'
import { writeBuildId } from './write-build-id'
Expand Down Expand Up @@ -162,7 +161,6 @@ import type { NextEnabledDirectories } from '../server/base-server'
import { hasCustomExportOutput } from '../export/utils'
import { interopDefault } from '../lib/interop-default'
import { formatDynamicImportPath } from '../lib/format-dynamic-import-path'
import { isDefaultRoute } from '../lib/is-default-route'
import { isInterceptionRouteAppPath } from '../server/future/helpers/interception-routes'

interface ExperimentalBypassForInfo {
Expand Down Expand Up @@ -934,9 +932,7 @@ export default async function build(
validFileMatcher.isAppRouterPage(absolutePath) ||
// For now we only collect the root /not-found page in the app
// directory as the 404 fallback
validFileMatcher.isRootNotFound(absolutePath) ||
// Default slots are also valid pages, and need to be considered during path normalization
validFileMatcher.isDefaultSlot(absolutePath),
validFileMatcher.isRootNotFound(absolutePath),
ignorePartFilter: (part) => part.startsWith('_'),
})
)
Expand Down Expand Up @@ -1795,10 +1791,7 @@ export default async function build(
pageType === 'app' &&
staticInfo?.rsc !== RSC_MODULE_TYPES.client

if (
(pageType === 'app' && !isReservedAppPage(page)) ||
(pageType === 'pages' && !isReservedPage(page))
) {
if (pageType === 'app' || !isReservedPage(page)) {
try {
let edgeInfo: any

Expand Down Expand Up @@ -2499,7 +2492,6 @@ export default async function build(
routes.forEach((route) => {
if (isDynamicRoute(page) && route === page) return
if (route === '/_not-found') return
if (isDefaultRoute(page)) return

const {
revalidate = appConfig.revalidate ?? false,
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/build/normalize-catchall-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export function normalizeCatchAllRoutes(
!appPaths[appPath].some((path) =>
hasMatchedSlots(path, catchAllRoute)
) &&
// check if the catch-all is not already matched by a default route or page route
!appPaths[`${appPath}/default`] &&
// check if appPath is a catch-all OR is not more specific than the catch-all
(isCatchAllRoute(appPath) || !isMoreSpecific(appPath, catchAllRoute))
) {
Expand Down
5 changes: 0 additions & 5 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ import { interopDefault } from '../lib/interop-default'
import type { PageExtensions } from './page-extensions-type'
import { formatDynamicImportPath } from '../lib/format-dynamic-import-path'
import { isInterceptionRouteAppPath } from '../server/future/helpers/interception-routes'
import { isDefaultRoute } from '../lib/is-default-route'

export type ROUTER_TYPE = 'pages' | 'app'

Expand Down Expand Up @@ -2124,10 +2123,6 @@ export function isReservedPage(page: string) {
return RESERVED_PAGE.test(page)
}

export function isReservedAppPage(page: string) {
return isDefaultRoute(page)
}

export function isAppBuiltinNotFoundPage(page: string) {
return /next[\\/]dist[\\/]client[\\/]components[\\/]not-found-error/.test(
page
Expand Down
10 changes: 3 additions & 7 deletions packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import isError from '../lib/is-error'
import { needsExperimentalReact } from '../lib/needs-experimental-react'
import { formatManifest } from '../build/manifests/formatter/format-manifest'
import { validateRevalidate } from '../server/lib/patch-fetch'
import { isDefaultRoute } from '../lib/is-default-route'

function divideSegments(number: number, segments: number): number[] {
const result = []
Expand Down Expand Up @@ -565,12 +564,9 @@ export async function exportAppImpl(

const filteredPaths = exportPaths.filter(
(route) =>
// Remove default routes -- they don't need to be exported
// and are only used for parallel route normalization
!isDefaultRoute(exportPathMap[route].page) &&
(exportPathMap[route]._isAppDir ||
// Remove API routes
!isAPIRoute(exportPathMap[route].page))
exportPathMap[route]._isAppDir ||
// Remove API routes
!isAPIRoute(exportPathMap[route].page)
)

if (filteredPaths.length !== exportPaths.length) {
Expand Down
3 changes: 0 additions & 3 deletions packages/next/src/lib/is-default-route.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/next/src/server/lib/find-page-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ export function createValidFileMatcher(
return validExtensionFileRegex.test(filePath) || isMetadataFile(filePath)
}

function isDefaultSlot(filePath: string) {
return filePath.endsWith(`default.${pageExtensions[0]}`)
}

function isRootNotFound(filePath: string) {
if (!appDirPath) {
return false
Expand All @@ -147,6 +143,5 @@ export function createValidFileMatcher(
isAppRouterPage,
isMetadataFile,
isRootNotFound,
isDefaultSlot,
}
}

0 comments on commit 771e29c

Please sign in to comment.