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 (

0 commit comments

Comments
 (0)