Skip to content

Commit

Permalink
Remove ineffective webpack rules and unused app-page context modules
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed May 7, 2024
1 parent bf89bee commit 6da53dd
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 48 deletions.
30 changes: 8 additions & 22 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,14 +1272,6 @@ export default async function getBaseWebpackConfig(
},
...(hasAppDir
? [
{
layer: WEBPACK_LAYERS.appRouteHandler,
test: new RegExp(
`private-next-app-dir\\/.*\\/route\\.(${pageExtensions.join(
'|'
)})$`
),
},
{
// Make sure that AsyncLocalStorage module instance is shared between server and client
// layers.
Expand Down Expand Up @@ -1699,23 +1691,17 @@ export default async function getBaseWebpackConfig(
'.shared-runtime'
)
const layer = resource.contextInfo.issuerLayer

let runtime

switch (layer) {
case WEBPACK_LAYERS.appRouteHandler:
runtime = 'app-route'
break
case WEBPACK_LAYERS.serverSideRendering:
case WEBPACK_LAYERS.reactServerComponents:
case WEBPACK_LAYERS.appPagesBrowser:
case WEBPACK_LAYERS.actionBrowser:
runtime = 'app-page'
break
default:
runtime = 'pages'
if (layer === WEBPACK_LAYERS.serverSideRendering) {
runtime = 'app-page'
} else if (!layer) {
runtime = 'pages'
} else {
throw new Error(
`shared-runtime module ${moduleName} cannot be used in ${layer} layer`
)
}

resource.request = `next/dist/server/future/route-modules/${runtime}/vendored/contexts/${moduleName}`
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,7 @@ export class NextTypesPlugin {
}
return
}
if (
mod.layer !== WEBPACK_LAYERS.reactServerComponents &&
mod.layer !== WEBPACK_LAYERS.appRouteHandler
)
return
if (mod.layer !== WEBPACK_LAYERS.reactServerComponents) return

const IS_LAYOUT = /[/\\]layout\.[^./\\]+$/.test(mod.resource)
const IS_PAGE = !IS_LAYOUT && /[/\\]page\.[^.]+$/.test(mod.resource)
Expand Down
9 changes: 2 additions & 7 deletions packages/next/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ const WEBPACK_LAYERS_NAMES = {
*/
shared: 'shared',
/**
* React Server Components layer (rsc).
* The layer for server-only runtime and picking up `react-server` export conditions.
* Including app router RSC pages and app router custom routes.
*/
reactServerComponents: 'rsc',
/**
Expand Down Expand Up @@ -150,10 +151,6 @@ const WEBPACK_LAYERS_NAMES = {
* The server bundle layer for metadata routes.
*/
appMetadataRoute: 'app-metadata-route',
/**
* The layer for the server bundle for App Route handlers.
*/
appRouteHandler: 'app-route-handler',
} as const

export type WebpackLayerName =
Expand All @@ -166,7 +163,6 @@ const WEBPACK_LAYERS = {
WEBPACK_LAYERS_NAMES.reactServerComponents,
WEBPACK_LAYERS_NAMES.actionBrowser,
WEBPACK_LAYERS_NAMES.appMetadataRoute,
WEBPACK_LAYERS_NAMES.appRouteHandler,
WEBPACK_LAYERS_NAMES.instrument,
],
clientOnly: [
Expand All @@ -182,7 +178,6 @@ const WEBPACK_LAYERS = {
WEBPACK_LAYERS_NAMES.reactServerComponents,
WEBPACK_LAYERS_NAMES.actionBrowser,
WEBPACK_LAYERS_NAMES.appMetadataRoute,
WEBPACK_LAYERS_NAMES.appRouteHandler,
WEBPACK_LAYERS_NAMES.serverSideRendering,
WEBPACK_LAYERS_NAMES.appPagesBrowser,
WEBPACK_LAYERS_NAMES.shared,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ export * as ServerInsertedHtml from '../../../../../../shared/lib/server-inserte
export * as AppRouterContext from '../../../../../../shared/lib/app-router-context.shared-runtime'
export * as HooksClientContext from '../../../../../../shared/lib/hooks-client-context.shared-runtime'
export * as RouterContext from '../../../../../../shared/lib/router-context.shared-runtime'
export * as HtmlContext from '../../../../../../shared/lib/html-context.shared-runtime'
export * as AmpContext from '../../../../../../shared/lib/amp-context.shared-runtime'
export * as LoadableContext from '../../../../../../shared/lib/loadable-context.shared-runtime'
export * as ImageConfigContext from '../../../../../../shared/lib/image-config-context.shared-runtime'
export * as Loadable from '../../../../../../shared/lib/loadable.shared-runtime'

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 6da53dd

Please sign in to comment.