diff --git a/packages/next/src/build/entries.ts b/packages/next/src/build/entries.ts index c606894ac9..d718564b47 100644 --- a/packages/next/src/build/entries.ts +++ b/packages/next/src/build/entries.ts @@ -85,11 +85,12 @@ export async function getStaticInfoIncludingLayouts({ } : pageStaticInfo - if (isInsideAppDir) { + if (isInsideAppDir && appDir) { const layoutFiles = [] const potentialLayoutFiles = pageExtensions.map((ext) => 'layout.' + ext) let dir = dirname(pageFilePath) - while (dir !== appDir) { + // Uses startsWith to not include directories further up. + while (dir.startsWith(appDir)) { for (const potentialLayoutFile of potentialLayoutFiles) { const layoutFile = join(dir, potentialLayoutFile) if (!(await fileExists(layoutFile))) { diff --git a/test/e2e/app-dir/app/app/layout.js b/test/e2e/app-dir/app/app/layout.js index 65adafbd7e..df63b571d2 100644 --- a/test/e2e/app-dir/app/app/layout.js +++ b/test/e2e/app-dir/app/app/layout.js @@ -4,6 +4,7 @@ import '../styles/global.css' import './style.css' export const revalidate = 0 +export const preferredRegion = 'sfo1' async function getData() { return { diff --git a/test/e2e/app-dir/app/index.test.ts b/test/e2e/app-dir/app/index.test.ts index 78a8175fbb..ca49e41ee3 100644 --- a/test/e2e/app-dir/app/index.test.ts +++ b/test/e2e/app-dir/app/index.test.ts @@ -29,6 +29,11 @@ createNextDescribe( expect(middlewareManifest.functions['/test-page/page'].regions).toEqual( ['home'] ) + + // Inherits from the root layout. + expect( + middlewareManifest.functions['/slow-page-with-loading/page'].regions + ).toEqual(['sfo1']) }) }