turbopack: don't generate implicit app not-found entrypoints for empty app directories - #1
Draft
thsid wants to merge 1 commit into
Draft
Conversation
An `app` directory that exists but has no real routes anywhere in it still got an implicit `_not-found`/`_global-error` route from Turbopack's app-dir entrypoint discovery, which shadowed a custom `pages/404` in production builds (`next build --turbopack`). The webpack/dev-mode fix in vercel#95713 didn't cover this path since Turbopack's production build enumerates app-dir entrypoints independently on the Rust side. Also flips the two Turbopack-production-build test cases in pages-404-with-empty-app-dir.test.ts from `it.failing` back to `it`, since this fix resolves them. Depends on vercel#95713.
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?
This fixes an inconsistency in Turbopack production builds where an app directory with no actual routes would still generate implicit
_not-foundand_global-errorentrypoints.As a result, a custom
pages/404could be incorrectly shadowed by the App Router's built-in not-found page, even though the App Router wasn't actually being used.This brings
next build --turbopackin line with the existing webpack/dev behavior introduced in vercel#95713.Why?
The Turbopack app entrypoint collection always generated implicit not-found/global-error entrypoints whenever an app directory existed, regardless of whether that directory contained any real routes.
This differed from the webpack logic, which only treats an app directory as active when it actually contains route files.
As a result, projects that primarily use the Pages Router—but still have an empty app directory (for example, after an abandoned App Router migration)—would unexpectedly lose their custom
pages/404.How?
directory_tree_has_any_route, which recursively checks whether an app directory tree contains any real route (page, route, not-found, or global-not-found)._not-foundand_global-errorentrypoints when no routes exist anywhere in the tree.it.failingexpectations from the regression test since Turbopack production builds now behave correctly.Testing
cargo check -p next-corecargo clippy -p next-core --no-depstest/e2e/app-dir/pages-404-with-empty-app-dirpasses in all four modes:next dev(webpack)next dev --turbopacknext build(webpack)next build --turbopacknot-found-with-pages-i18ncontinues to behave correctly, including in Turbopack production builds.not-found/basic, but confirmed it reproduces on the baseline without this change and is unrelated.Depends on vercel#95713