Unverified Commit 9ee7d7f7 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Revert "Remove ineffective webpack rules and unused app-page context modules" (#65558)

Reverts vercel/next.js#65321

Missed covering `api` layer, got reported with below error. Revert it
for now and will re-land it with more tests

```
../../node_modules/.pnpm/next@14.3.0-canary.51_@opentelemetry+api@1.7.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/client/components/navigation.js
02:23:13
Module not found: shared-runtime module app-router-context cannot be used in api layer
02:23:13
https://nextjs.org/docs/messages/module-not-found
```
parent 01db9854
...@@ -1275,6 +1275,14 @@ export default async function getBaseWebpackConfig( ...@@ -1275,6 +1275,14 @@ export default async function getBaseWebpackConfig(
}, },
...(hasAppDir ...(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 // Make sure that AsyncLocalStorage module instance is shared between server and client
// layers. // layers.
...@@ -1700,17 +1708,23 @@ export default async function getBaseWebpackConfig( ...@@ -1700,17 +1708,23 @@ export default async function getBaseWebpackConfig(
'.shared-runtime' '.shared-runtime'
) )
const layer = resource.contextInfo.issuerLayer const layer = resource.contextInfo.issuerLayer
let runtime let runtime
if (layer === WEBPACK_LAYERS.serverSideRendering) { switch (layer) {
runtime = 'app-page' case WEBPACK_LAYERS.appRouteHandler:
} else if (!layer) { runtime = 'app-route'
runtime = 'pages' break
} else { case WEBPACK_LAYERS.serverSideRendering:
throw new Error( case WEBPACK_LAYERS.reactServerComponents:
`shared-runtime module ${moduleName} cannot be used in ${layer} layer` case WEBPACK_LAYERS.appPagesBrowser:
) case WEBPACK_LAYERS.actionBrowser:
runtime = 'app-page'
break
default:
runtime = 'pages'
} }
resource.request = `next/dist/server/future/route-modules/${runtime}/vendored/contexts/${moduleName}` resource.request = `next/dist/server/future/route-modules/${runtime}/vendored/contexts/${moduleName}`
} }
), ),
......
...@@ -613,7 +613,11 @@ export class NextTypesPlugin { ...@@ -613,7 +613,11 @@ export class NextTypesPlugin {
} }
return return
} }
if (mod.layer !== WEBPACK_LAYERS.reactServerComponents) return if (
mod.layer !== WEBPACK_LAYERS.reactServerComponents &&
mod.layer !== WEBPACK_LAYERS.appRouteHandler
)
return
const IS_LAYOUT = /[/\\]layout\.[^./\\]+$/.test(mod.resource) const IS_LAYOUT = /[/\\]layout\.[^./\\]+$/.test(mod.resource)
const IS_PAGE = !IS_LAYOUT && /[/\\]page\.[^.]+$/.test(mod.resource) const IS_PAGE = !IS_LAYOUT && /[/\\]page\.[^.]+$/.test(mod.resource)
......
...@@ -115,8 +115,7 @@ const WEBPACK_LAYERS_NAMES = { ...@@ -115,8 +115,7 @@ const WEBPACK_LAYERS_NAMES = {
*/ */
shared: 'shared', shared: 'shared',
/** /**
* The layer for server-only runtime and picking up `react-server` export conditions. * React Server Components layer (rsc).
* Including app router RSC pages and app router custom routes.
*/ */
reactServerComponents: 'rsc', reactServerComponents: 'rsc',
/** /**
...@@ -151,6 +150,10 @@ const WEBPACK_LAYERS_NAMES = { ...@@ -151,6 +150,10 @@ const WEBPACK_LAYERS_NAMES = {
* The server bundle layer for metadata routes. * The server bundle layer for metadata routes.
*/ */
appMetadataRoute: 'app-metadata-route', appMetadataRoute: 'app-metadata-route',
/**
* The layer for the server bundle for App Route handlers.
*/
appRouteHandler: 'app-route-handler',
} as const } as const
export type WebpackLayerName = export type WebpackLayerName =
...@@ -163,6 +166,7 @@ const WEBPACK_LAYERS = { ...@@ -163,6 +166,7 @@ const WEBPACK_LAYERS = {
WEBPACK_LAYERS_NAMES.reactServerComponents, WEBPACK_LAYERS_NAMES.reactServerComponents,
WEBPACK_LAYERS_NAMES.actionBrowser, WEBPACK_LAYERS_NAMES.actionBrowser,
WEBPACK_LAYERS_NAMES.appMetadataRoute, WEBPACK_LAYERS_NAMES.appMetadataRoute,
WEBPACK_LAYERS_NAMES.appRouteHandler,
WEBPACK_LAYERS_NAMES.instrument, WEBPACK_LAYERS_NAMES.instrument,
], ],
clientOnly: [ clientOnly: [
...@@ -178,6 +182,7 @@ const WEBPACK_LAYERS = { ...@@ -178,6 +182,7 @@ const WEBPACK_LAYERS = {
WEBPACK_LAYERS_NAMES.reactServerComponents, WEBPACK_LAYERS_NAMES.reactServerComponents,
WEBPACK_LAYERS_NAMES.actionBrowser, WEBPACK_LAYERS_NAMES.actionBrowser,
WEBPACK_LAYERS_NAMES.appMetadataRoute, WEBPACK_LAYERS_NAMES.appMetadataRoute,
WEBPACK_LAYERS_NAMES.appRouteHandler,
WEBPACK_LAYERS_NAMES.serverSideRendering, WEBPACK_LAYERS_NAMES.serverSideRendering,
WEBPACK_LAYERS_NAMES.appPagesBrowser, WEBPACK_LAYERS_NAMES.appPagesBrowser,
WEBPACK_LAYERS_NAMES.shared, WEBPACK_LAYERS_NAMES.shared,
......
...@@ -3,5 +3,8 @@ export * as ServerInsertedHtml from '../../../../../../shared/lib/server-inserte ...@@ -3,5 +3,8 @@ export * as ServerInsertedHtml from '../../../../../../shared/lib/server-inserte
export * as AppRouterContext from '../../../../../../shared/lib/app-router-context.shared-runtime' export * as AppRouterContext from '../../../../../../shared/lib/app-router-context.shared-runtime'
export * as HooksClientContext from '../../../../../../shared/lib/hooks-client-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 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 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 ImageConfigContext from '../../../../../../shared/lib/image-config-context.shared-runtime'
export * as Loadable from '../../../../../../shared/lib/loadable.shared-runtime'
module.exports = require('../../module.compiled').vendored[
'contexts'
].HtmlContext
module.exports = require('../../module.compiled').vendored[
'contexts'
].LoadableContext
module.exports = require('../../module.compiled').vendored['contexts'].Loadable
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment