Skip to content

Commit

Permalink
Enabel appDir when flag and dir existed at the same time (#41233)
Browse files Browse the repository at this point in the history
If there's an existing folder named `app/` but `appDir` flag is not
enabled, do not enabled server components
  • Loading branch information
huozhi committed Oct 6, 2022
1 parent 87026c8 commit f83cc0c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/preset.js
Expand Up @@ -7,7 +7,7 @@ const CWD = process.cwd()

async function webpackFinal(config) {
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, {
pagesDir,
entrypoints: {},
Expand Down
8 changes: 4 additions & 4 deletions packages/next/build/index.ts
Expand Up @@ -301,8 +301,8 @@ export default async function build(
setGlobal('telemetry', telemetry)

const publicDir = path.join(dir, 'public')
const hasAppDir = !!config.experimental.appDir
const { pagesDir, appDir } = findPagesDir(dir, hasAppDir)
const isAppDirEnabled = !!config.experimental.appDir
const { pagesDir, appDir } = findPagesDir(dir, isAppDirEnabled)

const hasPublicDir = await fileExists(publicDir)

Expand Down Expand Up @@ -394,7 +394,7 @@ export default async function build(
config.experimental.cpus,
config.experimental.workerThreads,
telemetry,
hasAppDir
isAppDirEnabled && !!appDir
)
}),
])
Expand Down Expand Up @@ -1988,7 +1988,7 @@ export default async function build(
combinedPages.length > 0 ||
useStatic404 ||
useDefaultStatic500 ||
hasAppDir
isAppDirEnabled
) {
const staticGenerationSpan =
nextBuildSpan.traceChild('static-generation')
Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/jest/jest.ts
Expand Up @@ -72,8 +72,8 @@ export default function nextJest(options: { dir?: string } = {}) {
isEsmProject = packageConfig.type === 'module'

nextConfig = await getConfig(resolvedDir)
const hasAppDir = !!nextConfig.experimental.appDir
const findPagesDirResult = findPagesDir(resolvedDir, hasAppDir)
const isAppDirEnabled = !!nextConfig.experimental.appDir
const findPagesDirResult = findPagesDir(resolvedDir, isAppDirEnabled)
hasServerComponents = !!findPagesDirResult.appDir
pagesDir = findPagesDirResult.pagesDir
setUpEnv(resolvedDir, nextConfig)
Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/webpack-config.ts
Expand Up @@ -563,7 +563,7 @@ export default async function getBaseWebpackConfig(
rewrites.afterFiles.length > 0 ||
rewrites.fallback.length > 0

const hasAppDir = !!config.experimental.appDir
const hasAppDir = !!config.experimental.appDir && !!appDir
const hasConcurrentFeatures = hasReactRoot
const hasServerComponents = hasAppDir

Expand Down Expand Up @@ -1587,7 +1587,7 @@ export default async function getBaseWebpackConfig(
]
: []),
// Alias `next/dynamic` to React.lazy implementation for RSC
...(hasServerComponents && appDir
...(hasServerComponents
? [
{
test: codeCondition.test,
Expand Down
3 changes: 2 additions & 1 deletion packages/next/server/base-server.ts
Expand Up @@ -368,7 +368,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this.buildId = this.getBuildId()
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
this.serverComponentManifest = serverComponents
? this.getServerComponentManifest()
Expand Down
5 changes: 4 additions & 1 deletion packages/next/server/dev/next-dev-server.ts
Expand Up @@ -191,7 +191,10 @@ export default class DevServer extends Server {

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.appDir = appDir
}
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/streaming-ssr/index.test.ts
Expand Up @@ -22,6 +22,11 @@ describe('react 18 streaming SSR with custom next configs', () => {
beforeAll(async () => {
next = await createNext({
files: {
'app/page.js': `
export default function Page() {
return 'fake-app' /* this should not enable appDir */
}
`,
pages: new FileRef(join(__dirname, 'streaming-ssr/pages')),
},
nextConfig: require(join(__dirname, 'streaming-ssr/next.config.js')),
Expand Down

0 comments on commit f83cc0c

Please sign in to comment.