From 3bd396f165cd5cadb9875731729c8b91425d7179 Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Fri, 26 Jan 2024 16:46:06 -0800 Subject: [PATCH] revert changes to process default routes at build --- packages/next/src/build/index.ts | 12 ++---------- packages/next/src/build/normalize-catchall-routes.ts | 2 -- packages/next/src/build/utils.ts | 5 ----- .../src/build/webpack/plugins/middleware-plugin.ts | 1 + packages/next/src/export/index.ts | 10 +++------- packages/next/src/lib/is-default-route.ts | 3 --- packages/next/src/server/lib/find-page-file.ts | 5 ----- 7 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 packages/next/src/lib/is-default-route.ts diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index ac431bb8acef3..41972bed3bf01 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -115,7 +115,6 @@ import { isReservedPage, isAppBuiltinNotFoundPage, serializePageInfos, - isReservedAppPage, } from './utils' import type { PageInfo, PageInfos, AppConfig } from './utils' import { writeBuildId } from './write-build-id' @@ -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 { @@ -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('_'), }) ) @@ -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 @@ -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, diff --git a/packages/next/src/build/normalize-catchall-routes.ts b/packages/next/src/build/normalize-catchall-routes.ts index 6df6c46a136d6..8186688770a28 100644 --- a/packages/next/src/build/normalize-catchall-routes.ts +++ b/packages/next/src/build/normalize-catchall-routes.ts @@ -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)) ) { diff --git a/packages/next/src/build/utils.ts b/packages/next/src/build/utils.ts index efc3ee3557c44..f8ddd8b4c74a7 100644 --- a/packages/next/src/build/utils.ts +++ b/packages/next/src/build/utils.ts @@ -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' @@ -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 diff --git a/packages/next/src/build/webpack/plugins/middleware-plugin.ts b/packages/next/src/build/webpack/plugins/middleware-plugin.ts index aea342d47a283..7bba168003386 100644 --- a/packages/next/src/build/webpack/plugins/middleware-plugin.ts +++ b/packages/next/src/build/webpack/plugins/middleware-plugin.ts @@ -172,6 +172,7 @@ function getCreateAssets(params: { metadata?.edgeMiddleware?.page || metadata?.edgeSSR?.page || metadata?.edgeApiFunction?.page + if (!page) { continue } diff --git a/packages/next/src/export/index.ts b/packages/next/src/export/index.ts index b07ca09bdc863..28d6921259067 100644 --- a/packages/next/src/export/index.ts +++ b/packages/next/src/export/index.ts @@ -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 = [] @@ -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) { diff --git a/packages/next/src/lib/is-default-route.ts b/packages/next/src/lib/is-default-route.ts deleted file mode 100644 index adbd42d508f7f..0000000000000 --- a/packages/next/src/lib/is-default-route.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isDefaultRoute(value?: string) { - return value?.endsWith('/default') -} diff --git a/packages/next/src/server/lib/find-page-file.ts b/packages/next/src/server/lib/find-page-file.ts index 42b046e8efc54..d51935a761d17 100644 --- a/packages/next/src/server/lib/find-page-file.ts +++ b/packages/next/src/server/lib/find-page-file.ts @@ -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 @@ -147,6 +143,5 @@ export function createValidFileMatcher( isAppRouterPage, isMetadataFile, isRootNotFound, - isDefaultSlot, } }