fix(next-dev): don't let an app dir without real routes override pages/404#95713
Open
thsid wants to merge 2 commits into
Open
fix(next-dev): don't let an app dir without real routes override pages/404#95713thsid wants to merge 2 commits into
thsid wants to merge 2 commits into
Conversation
An `app` directory that exists but has no real app routes (e.g. only a root layout) incorrectly hijacked 404 handling away from a custom `pages/404`, because dev-mode page resolution unconditionally fell back to the built-in not-found component whenever the `app` directory existed, regardless of whether it had any real routes. Fixes vercel#58945
findPagePathData fell back to a full recursive walk of the app directory (via collectAppFiles) to check whether it had any real routes, on every 404 request without a custom not-found file. Since ensurePage only dedupes concurrent calls, this ran on every distinct 404, not just once. Add a stopAfterFirstMatch option to recursiveReadDir and a hasAppRoutes helper that stops as soon as a single route is found, so a normal app (with a root layout) resolves after reading just the top-level directory instead of walking the whole tree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fixes a bug where the mere presence of an
appdirectory — even one with no real routes in it — would overridepages/404, instead of falling back to it as expected.Why?
The 404 page resolution logic treated the existence of the
appdirectory itself as a signal that an app-dir 404 should take precedence, rather than checking whether the app dir actually defines any routes. This causedpages/404to be silently shadowed in projects that have an (effectively empty)appdirectory alongside apagesdirectory.How?
next devcorrectly falls back topages/404when theappdirectory contains no real routes. Covers both the webpack and Turbopack dev paths.next buildwith webpack was already handled correctly by a prior fix and required no change here.test/e2e/app-dir/pages-404-with-empty-app-dir.Known remaining issue
next build --turbopack(production build) is not fixed by this PR — the root cause there is on the Rust side, in how Turbopack enumerates entrypoints, which is out of scope for this change. This case is covered by a test marked withit.failingto track it explicitly rather than leave it silently broken.Fixes #58945