Unverified Commit f83cc0cb authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Enabel appDir when flag and dir existed at the same time (#41233)

If there's an existing folder named `app/` but `appDir` flag is not
enabled, do not enabled server components
parent 87026c89
...@@ -7,7 +7,7 @@ const CWD = process.cwd() ...@@ -7,7 +7,7 @@ const CWD = process.cwd()
async function webpackFinal(config) { async function webpackFinal(config) {
const nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, CWD) const nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, CWD)
const pagesDir = findPagesDir(CWD, !!nextConfig.experimental.appDir) const { pagesDir } = findPagesDir(CWD, !!nextConfig.experimental.appDir)
const nextWebpackConfig = await getWebpackConfig(CWD, { const nextWebpackConfig = await getWebpackConfig(CWD, {
pagesDir, pagesDir,
entrypoints: {}, entrypoints: {},
......
...@@ -301,8 +301,8 @@ export default async function build( ...@@ -301,8 +301,8 @@ export default async function build(
setGlobal('telemetry', telemetry) setGlobal('telemetry', telemetry)
const publicDir = path.join(dir, 'public') const publicDir = path.join(dir, 'public')
const hasAppDir = !!config.experimental.appDir const isAppDirEnabled = !!config.experimental.appDir
const { pagesDir, appDir } = findPagesDir(dir, hasAppDir) const { pagesDir, appDir } = findPagesDir(dir, isAppDirEnabled)
const hasPublicDir = await fileExists(publicDir) const hasPublicDir = await fileExists(publicDir)
...@@ -394,7 +394,7 @@ export default async function build( ...@@ -394,7 +394,7 @@ export default async function build(
config.experimental.cpus, config.experimental.cpus,
config.experimental.workerThreads, config.experimental.workerThreads,
telemetry, telemetry,
hasAppDir isAppDirEnabled && !!appDir
) )
}), }),
]) ])
...@@ -1988,7 +1988,7 @@ export default async function build( ...@@ -1988,7 +1988,7 @@ export default async function build(
combinedPages.length > 0 || combinedPages.length > 0 ||
useStatic404 || useStatic404 ||
useDefaultStatic500 || useDefaultStatic500 ||
hasAppDir isAppDirEnabled
) { ) {
const staticGenerationSpan = const staticGenerationSpan =
nextBuildSpan.traceChild('static-generation') nextBuildSpan.traceChild('static-generation')
......
...@@ -72,8 +72,8 @@ export default function nextJest(options: { dir?: string } = {}) { ...@@ -72,8 +72,8 @@ export default function nextJest(options: { dir?: string } = {}) {
isEsmProject = packageConfig.type === 'module' isEsmProject = packageConfig.type === 'module'
nextConfig = await getConfig(resolvedDir) nextConfig = await getConfig(resolvedDir)
const hasAppDir = !!nextConfig.experimental.appDir const isAppDirEnabled = !!nextConfig.experimental.appDir
const findPagesDirResult = findPagesDir(resolvedDir, hasAppDir) const findPagesDirResult = findPagesDir(resolvedDir, isAppDirEnabled)
hasServerComponents = !!findPagesDirResult.appDir hasServerComponents = !!findPagesDirResult.appDir
pagesDir = findPagesDirResult.pagesDir pagesDir = findPagesDirResult.pagesDir
setUpEnv(resolvedDir, nextConfig) setUpEnv(resolvedDir, nextConfig)
......
...@@ -563,7 +563,7 @@ export default async function getBaseWebpackConfig( ...@@ -563,7 +563,7 @@ export default async function getBaseWebpackConfig(
rewrites.afterFiles.length > 0 || rewrites.afterFiles.length > 0 ||
rewrites.fallback.length > 0 rewrites.fallback.length > 0
const hasAppDir = !!config.experimental.appDir const hasAppDir = !!config.experimental.appDir && !!appDir
const hasConcurrentFeatures = hasReactRoot const hasConcurrentFeatures = hasReactRoot
const hasServerComponents = hasAppDir const hasServerComponents = hasAppDir
...@@ -1587,7 +1587,7 @@ export default async function getBaseWebpackConfig( ...@@ -1587,7 +1587,7 @@ export default async function getBaseWebpackConfig(
] ]
: []), : []),
// Alias `next/dynamic` to React.lazy implementation for RSC // Alias `next/dynamic` to React.lazy implementation for RSC
...(hasServerComponents && appDir ...(hasServerComponents
? [ ? [
{ {
test: codeCondition.test, test: codeCondition.test,
......
...@@ -368,7 +368,8 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -368,7 +368,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this.buildId = this.getBuildId() this.buildId = this.getBuildId()
this.minimalMode = minimalMode || !!process.env.NEXT_PRIVATE_MINIMAL_MODE this.minimalMode = minimalMode || !!process.env.NEXT_PRIVATE_MINIMAL_MODE
this.hasAppDir = this.getHasAppDir(dev) this.hasAppDir =
!!this.nextConfig.experimental.appDir && this.getHasAppDir(dev)
const serverComponents = this.hasAppDir const serverComponents = this.hasAppDir
this.serverComponentManifest = serverComponents this.serverComponentManifest = serverComponents
? this.getServerComponentManifest() ? this.getServerComponentManifest()
......
...@@ -191,7 +191,10 @@ export default class DevServer extends Server { ...@@ -191,7 +191,10 @@ export default class DevServer extends Server {
this.isCustomServer = !options.isNextDevCommand this.isCustomServer = !options.isNextDevCommand
const { pagesDir, appDir } = findPagesDir(this.dir, this.hasAppDir) const { pagesDir, appDir } = findPagesDir(
this.dir,
!!this.nextConfig.experimental.appDir
)
this.pagesDir = pagesDir this.pagesDir = pagesDir
this.appDir = appDir this.appDir = appDir
} }
......
...@@ -22,6 +22,11 @@ describe('react 18 streaming SSR with custom next configs', () => { ...@@ -22,6 +22,11 @@ describe('react 18 streaming SSR with custom next configs', () => {
beforeAll(async () => { beforeAll(async () => {
next = await createNext({ next = await createNext({
files: { files: {
'app/page.js': `
export default function Page() {
return 'fake-app' /* this should not enable appDir */
}
`,
pages: new FileRef(join(__dirname, 'streaming-ssr/pages')), pages: new FileRef(join(__dirname, 'streaming-ssr/pages')),
}, },
nextConfig: require(join(__dirname, 'streaming-ssr/next.config.js')), nextConfig: require(join(__dirname, 'streaming-ssr/next.config.js')),
......
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