Skip to content

Commit 71cdce6

Browse files
authored
[refactor] group the built-in conventions (#80957)
Group all the built-in conventions into `src/client/components/builtin` with the actual same name of the conventions they represent. e.g. The default `not-found.js` is `next/dist/client/compoents/builtin/not-found.js`; The default `global-error.js` is `next/dist/client/compoents/builtin/global-error.js`; This give us an easier way to track all the builtin conventions. This is also the preparation work for #80961 where we display the builtin conventions in the segment explorer.
1 parent ee5c6eb commit 71cdce6

File tree

23 files changed

+41
-40
lines changed

23 files changed

+41
-40
lines changed

crates/next-core/src/app_structure.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -910,23 +910,23 @@ async fn directory_tree_to_loader_tree_internal(
910910
if modules.not_found.is_none() {
911911
modules.not_found = Some(
912912
get_next_package(app_dir)
913-
.join(rcstr!("dist/client/components/not-found-error.js"))
913+
.join(rcstr!("dist/client/components/builtin/not-found.js"))
914914
.to_resolved()
915915
.await?,
916916
);
917917
}
918918
if modules.forbidden.is_none() {
919919
modules.forbidden = Some(
920920
get_next_package(app_dir)
921-
.join(rcstr!("dist/client/components/forbidden-error.js"))
921+
.join(rcstr!("dist/client/components/builtin/forbidden.js"))
922922
.to_resolved()
923923
.await?,
924924
);
925925
}
926926
if modules.unauthorized.is_none() {
927927
modules.unauthorized = Some(
928928
get_next_package(app_dir)
929-
.join(rcstr!("dist/client/components/unauthorized-error.js"))
929+
.join(rcstr!("dist/client/components/builtin/unauthorized.js"))
930930
.to_resolved()
931931
.await?,
932932
);
@@ -1130,7 +1130,7 @@ async fn default_route_tree(
11301130
AppDirModules {
11311131
default: Some(
11321132
get_next_package(app_dir)
1133-
.join(rcstr!("dist/client/components/parallel-route-default.js"))
1133+
.join(rcstr!("dist/client/components/builtin/default.js"))
11341134
.to_resolved()
11351135
.await?,
11361136
),
@@ -1275,7 +1275,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
12751275
if modules.layout.is_none() {
12761276
modules.layout = Some(
12771277
get_next_package(*app_dir)
1278-
.join(rcstr!("dist/client/components/default-layout.js"))
1278+
.join(rcstr!("dist/client/components/builtin/layout.js"))
12791279
.to_resolved()
12801280
.await?,
12811281
);
@@ -1284,23 +1284,23 @@ async fn directory_tree_to_entrypoints_internal_untraced(
12841284
if modules.not_found.is_none() {
12851285
modules.not_found = Some(
12861286
get_next_package(*app_dir)
1287-
.join(rcstr!("dist/client/components/not-found-error.js"))
1287+
.join(rcstr!("dist/client/components/builtin/not-found.js"))
12881288
.to_resolved()
12891289
.await?,
12901290
);
12911291
}
12921292
if modules.forbidden.is_none() {
12931293
modules.forbidden = Some(
12941294
get_next_package(*app_dir)
1295-
.join(rcstr!("dist/client/components/forbidden-error.js"))
1295+
.join(rcstr!("dist/client/components/builtin/forbidden.js"))
12961296
.to_resolved()
12971297
.await?,
12981298
);
12991299
}
13001300
if modules.unauthorized.is_none() {
13011301
modules.unauthorized = Some(
13021302
get_next_package(*app_dir)
1303-
.join(rcstr!("dist/client/components/unauthorized-error.js"))
1303+
.join(rcstr!("dist/client/components/builtin/unauthorized.js"))
13041304
.to_resolved()
13051305
.await?,
13061306
);
@@ -1335,7 +1335,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
13351335
page: match modules.global_not_found {
13361336
Some(v) => Some(v),
13371337
None => Some(get_next_package(*app_dir)
1338-
.join(rcstr!("dist/client/components/global-not-found.js"))
1338+
.join(rcstr!("dist/client/components/builtin/global-not-found.js"))
13391339
.to_resolved()
13401340
.await?),
13411341
},
@@ -1348,7 +1348,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
13481348
page: match modules.not_found {
13491349
Some(v) => Some(v),
13501350
None => Some(get_next_package(*app_dir)
1351-
.join(rcstr!("dist/client/components/not-found-error.js"))
1351+
.join(rcstr!("dist/client/components/builtin/not-found.js"))
13521352
.to_resolved()
13531353
.await?),
13541354
},

crates/next-core/src/next_app/app_page_entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub async fn get_app_page_entry(
8888
"VAR_MODULE_GLOBAL_ERROR" => if inner_assets.contains_key(GLOBAL_ERROR) {
8989
GLOBAL_ERROR.into()
9090
} else {
91-
"next/dist/client/components/global-error".into()
91+
"next/dist/client/components/builtin/global-error".into()
9292
},
9393
},
9494
fxindexmap! {

packages/next/src/build/entries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export async function createPagesMapping({
305305
// If there's any custom /_not-found page, it will override the default one.
306306
...(hasAppPages && {
307307
[UNDERSCORE_NOT_FOUND_ROUTE_ENTRY]: require.resolve(
308-
'next/dist/client/components/global-not-found'
308+
'next/dist/client/components/builtin/global-not-found'
309309
),
310310
}),
311311
...pages,

packages/next/src/build/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ export default async function build(
18841884

18851885
const pageFilePath = isAppBuiltinNotFoundPage(pagePath)
18861886
? require.resolve(
1887-
'next/dist/client/components/not-found-error'
1887+
'next/dist/client/components/builtin/not-found'
18881888
)
18891889
: path.join(
18901890
(pageType === 'pages' ? pagesDir : appDir) || '',

packages/next/src/build/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ export function isReservedPage(page: string) {
17561756
}
17571757

17581758
export function isAppBuiltinNotFoundPage(page: string) {
1759-
return /next[\\/]dist[\\/]client[\\/]components[\\/](not-found-error|global-not-found)/.test(
1759+
return /next[\\/]dist[\\/]client[\\/]components[\\/]builtin[\\/](not-found|global-not-found)/.test(
17601760
page
17611761
)
17621762
}

packages/next/src/build/webpack/loaders/next-app-loader/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from '../../../../shared/lib/segment'
3131
import { getFilesInDir } from '../../../../lib/get-files-in-dir'
3232
import type { PageExtensions } from '../../../page-extensions-type'
33-
import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../../../client/components/parallel-route-default'
33+
import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../../../client/components/builtin/default'
3434
import type { Compilation } from 'webpack'
3535
import { createAppRouteCode } from './create-app-route-code'
3636

@@ -59,9 +59,9 @@ const HTTP_ACCESS_FALLBACKS = {
5959
unauthorized: 'unauthorized',
6060
} as const
6161
const defaultHTTPAccessFallbackPaths = {
62-
'not-found': 'next/dist/client/components/not-found-error',
63-
forbidden: 'next/dist/client/components/forbidden-error',
64-
unauthorized: 'next/dist/client/components/unauthorized-error',
62+
'not-found': 'next/dist/client/components/builtin/not-found.js',
63+
forbidden: 'next/dist/client/components/builtin/forbidden.js',
64+
unauthorized: 'next/dist/client/components/builtin/unauthorized.js',
6565
} as const
6666

6767
const FILE_TYPES = {
@@ -79,11 +79,12 @@ const GLOBAL_NOT_FOUND_FILE_TYPE = 'global-not-found'
7979
const PAGE_SEGMENT = 'page$'
8080
const PARALLEL_CHILDREN_SEGMENT = 'children$'
8181

82-
const defaultGlobalErrorPath = 'next/dist/client/components/global-error.js'
83-
const defaultNotFoundPath = 'next/dist/client/components/not-found-error.js'
84-
const defaultLayoutPath = 'next/dist/client/components/default-layout.js'
82+
const defaultGlobalErrorPath =
83+
'next/dist/client/components/builtin/global-error.js'
84+
const defaultNotFoundPath = 'next/dist/client/components/builtin/not-found.js'
85+
const defaultLayoutPath = 'next/dist/client/components/builtin/layout.js'
8586
const defaultGlobalNotFoundPath =
86-
'next/dist/client/components/global-not-found.js'
87+
'next/dist/client/components/builtin/global-not-found.js'
8788

8889
type DirResolver = (pathToResolve: string) => string
8990
type PathResolver = (

packages/next/src/client/components/app-router-instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
import { setLinkForCurrentNavigation, type LinkInstance } from './links'
2828
import type { FlightRouterState } from '../../server/app-render/types'
2929
import type { ClientInstrumentationHooks } from '../app-index'
30-
import type { GlobalErrorComponent } from './global-error'
30+
import type { GlobalErrorComponent } from './builtin/global-error'
3131

3232
export type DispatchStatePromise = React.Dispatch<ReducerState>
3333

packages/next/src/client/components/app-router.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from '../../shared/lib/hooks-client-context.shared-runtime'
2424
import { dispatchAppRouterAction, useActionQueue } from './use-action-queue'
2525
import { ErrorBoundary } from './error-boundary'
26-
import DefaultGlobalError from '../../client/components/global-error'
26+
import DefaultGlobalError from './builtin/global-error'
2727
import { isBot } from '../../shared/lib/router/utils/is-bot'
2828
import { addBasePath } from '../add-base-path'
2929
import { AppRouterAnnouncer } from './app-router-announcer'

packages/next/src/client/components/parallel-route-default.tsx renamed to packages/next/src/client/components/builtin/default.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { notFound } from './not-found'
1+
import { notFound } from '../not-found'
22

33
export const PARALLEL_ROUTE_DEFAULT_PATH =
4-
'next/dist/client/components/parallel-route-default.js'
4+
'next/dist/client/components/builtin/default.js'
55

66
export default function ParallelRouteDefault() {
77
notFound()

packages/next/src/client/components/forbidden-error.tsx renamed to packages/next/src/client/components/builtin/forbidden.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTTPAccessErrorFallback } from './http-access-fallback/error-fallback'
1+
import { HTTPAccessErrorFallback } from '../http-access-fallback/error-fallback'
22

33
export default function Forbidden() {
44
return (

packages/next/src/client/components/global-error.tsx renamed to packages/next/src/client/components/builtin/global-error.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { HandleISRError } from './handle-isr-error'
3+
import { HandleISRError } from '../handle-isr-error'
44

55
const styles = {
66
error: {

packages/next/src/client/components/global-not-found.tsx renamed to packages/next/src/client/components/builtin/global-not-found.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTTPAccessErrorFallback } from './http-access-fallback/error-fallback'
1+
import { HTTPAccessErrorFallback } from '../http-access-fallback/error-fallback'
22

33
function GlobalNotFound() {
44
return (

packages/next/src/client/components/not-found-error.tsx renamed to packages/next/src/client/components/builtin/not-found.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTTPAccessErrorFallback } from './http-access-fallback/error-fallback'
1+
import { HTTPAccessErrorFallback } from '../http-access-fallback/error-fallback'
22

33
export default function NotFound() {
44
return (

packages/next/src/client/components/unauthorized-error.tsx renamed to packages/next/src/client/components/builtin/unauthorized.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTTPAccessErrorFallback } from './http-access-fallback/error-fallback'
1+
import { HTTPAccessErrorFallback } from '../http-access-fallback/error-fallback'
22

33
export default function Unauthorized() {
44
return (

packages/next/src/client/react-client-callbacks/error-boundary-callbacks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-cs
1212
import { reportGlobalError } from './report-global-error'
1313
import { originConsoleError } from '../../next-devtools/userspace/app/errors/intercept-console-error'
1414
import { ErrorBoundaryHandler } from '../components/error-boundary'
15-
import DefaultErrorBoundary from '../components/global-error'
15+
import DefaultErrorBoundary from '../components/builtin/global-error'
1616

1717
export function onCaughtError(
1818
thrownValue: unknown,

packages/next/src/next-devtools/userspace/app/app-dev-overlay-error-boundary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PureComponent } from 'react'
22
import { dispatcher } from 'next/dist/compiled/next-devtools'
33
import { RuntimeErrorHandler } from '../../../client/dev/runtime-error-handler'
44
import { ErrorBoundary } from '../../../client/components/error-boundary'
5-
import DefaultGlobalError from '../../../client/components/global-error'
5+
import DefaultGlobalError from '../../../client/components/builtin/global-error'
66
import type { GlobalErrorState } from '../../../client/components/app-router-instance'
77

88
type AppDevOverlayErrorBoundaryProps = {

packages/next/src/next-devtools/userspace/app/client-entry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { getSocketUrl } from '../../../client/dev/hot-reloader/get-socket-url'
33
import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../../server/dev/hot-reloader-types'
4-
import DefaultGlobalError from '../../../client/components/global-error'
4+
import DefaultGlobalError from '../../../client/components/builtin/global-error'
55
import { AppDevOverlayErrorBoundary } from './app-dev-overlay-error-boundary'
66

77
// if an error is thrown while rendering an RSC stream, this will catch it in dev

packages/next/src/server/app-render/app-render.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ import {
199199
trackPendingModules,
200200
} from './module-loading/track-module-loading.external'
201201
import { isReactLargeShellError } from './react-large-shell-error'
202-
import type { GlobalErrorComponent } from '../../client/components/global-error'
202+
import type { GlobalErrorComponent } from '../../client/components/builtin/global-error'
203203

204204
export type GetDynamicParamFromSegment = (
205205
// [slug] / [[slug]] / [...slug]

packages/next/src/server/app-render/create-component-tree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { createComponentStylesAndScripts } from './create-component-styles-and-s
1313
import { getLayerAssets } from './get-layer-assets'
1414
import { hasLoadingComponentInTree } from './has-loading-component-in-tree'
1515
import { validateRevalidate } from '../lib/patch-fetch'
16-
import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../client/components/parallel-route-default'
16+
import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../client/components/builtin/default'
1717
import { getTracer } from '../lib/trace/tracer'
1818
import { NextNodeServerSpan } from '../lib/trace/constants'
1919
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout'
@@ -1109,7 +1109,7 @@ export function normalizeConventionFilePath(
11091109
) {
11101110
const cwd = process.env.NEXT_RUNTIME === 'edge' ? '' : process.cwd()
11111111
const nextInternalPrefixRegex =
1112-
/^(.*[\\/])?next[\\/]dist[\\/]client[\\/]components[\\/]/
1112+
/^(.*[\\/])?next[\\/]dist[\\/]client[\\/]components[\\/]builtin[\\/]/
11131113

11141114
let relativePath = (conventionPath || '')
11151115
// remove turbopack [project] prefix

packages/next/src/server/app-render/entry-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { patchFetch as _patchFetch } from '../lib/patch-fetch'
3333
// * ErrorBoundary -> client/components/error-boundary
3434
// * GlobalError -> client/components/global-error
3535
import '../../client/components/error-boundary'
36-
import '../../client/components/global-error'
36+
import '../../client/components/builtin/global-error'
3737
import {
3838
MetadataBoundary,
3939
ViewportBoundary,

packages/next/src/server/dev/on-demand-entry-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ export async function findPagePathData(
473473
// If they're not presented, then fallback to global-not-found
474474
return {
475475
filename: require.resolve(
476-
'next/dist/client/components/global-not-found'
476+
'next/dist/client/components/builtin/global-not-found'
477477
),
478478
bundlePath: `app${UNDERSCORE_NOT_FOUND_ROUTE_ENTRY}`,
479479
page: UNDERSCORE_NOT_FOUND_ROUTE_ENTRY,

test/development/app-dir/segment-explorer/segment-explorer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('segment-explorer', () => {
120120
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
121121
"app/
122122
layout.tsx
123-
not-found-error.js"
123+
not-found.js"
124124
`)
125125
})
126126

0 commit comments

Comments
 (0)