Skip to content

Commit ec8e0f9

Browse files
authored
Ensure app/layout.tsx can export preferredRegion (#49031)
Fixes a small bug where `layout` directly under `app` wasn't considered. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation or adding/fixing Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
1 parent 0b07616 commit ec8e0f9

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

packages/next/src/build/entries.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ export async function getStaticInfoIncludingLayouts({
8585
}
8686
: pageStaticInfo
8787

88-
if (isInsideAppDir) {
88+
if (isInsideAppDir && appDir) {
8989
const layoutFiles = []
9090
const potentialLayoutFiles = pageExtensions.map((ext) => 'layout.' + ext)
9191
let dir = dirname(pageFilePath)
92-
while (dir !== appDir) {
92+
// Uses startsWith to not include directories further up.
93+
while (dir.startsWith(appDir)) {
9394
for (const potentialLayoutFile of potentialLayoutFiles) {
9495
const layoutFile = join(dir, potentialLayoutFile)
9596
if (!(await fileExists(layoutFile))) {

test/e2e/app-dir/app/app/layout.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import '../styles/global.css'
44
import './style.css'
55

66
export const revalidate = 0
7+
export const preferredRegion = 'sfo1'
78

89
async function getData() {
910
return {

test/e2e/app-dir/app/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ createNextDescribe(
2929
expect(middlewareManifest.functions['/test-page/page'].regions).toEqual(
3030
['home']
3131
)
32+
33+
// Inherits from the root layout.
34+
expect(
35+
middlewareManifest.functions['/slow-page-with-loading/page'].regions
36+
).toEqual(['sfo1'])
3237
})
3338
}
3439

0 commit comments

Comments
 (0)