Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack: ensure default layout is provided in default not-found entrypoint #76912

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions crates/next-core/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,43 @@ async fn directory_tree_to_entrypoints_internal_untraced(
);
}

let mut modules = directory_tree.modules.clone();

// fill in the default modules for the not-found entrypoint
if modules.layout.is_none() {
modules.layout = Some(
get_next_package(*app_dir)
.join("dist/client/components/default-layout.js".into())
.to_resolved()
.await?,
);
}

if modules.not_found.is_none() {
modules.not_found = Some(
get_next_package(*app_dir)
.join("dist/client/components/not-found-error.js".into())
.to_resolved()
.await?,
);
}
if modules.forbidden.is_none() {
modules.forbidden = Some(
get_next_package(*app_dir)
.join("dist/client/components/forbidden-error.js".into())
.to_resolved()
.await?,
);
}
if modules.unauthorized.is_none() {
modules.unauthorized = Some(
get_next_package(*app_dir)
.join("dist/client/components/unauthorized-error.js".into())
.to_resolved()
.await?,
);
}

// Next.js has this logic in "collect-app-paths", where the root not-found page
// is considered as its own entry point.
let not_found_tree = AppPageLoaderTree {
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/app-dir/app-root-params/simple.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { nextTestSetup } from 'e2e-utils'
import { assertNoRedbox } from 'next-test-utils'
import { join } from 'path'

describe('app-root-params - simple', () => {
Expand All @@ -17,6 +18,14 @@ describe('app-root-params - simple', () => {
expect($('#root-params').text()).toBe('{"lang":"en","locale":"us"}')
})

it('should render the not found page without errors', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('h2').text()).toBe(
'This page could not be found.'
)
await assertNoRedbox(browser)
})

// `next-types-plugin` currently only runs in Webpack.
// We skip deployment mode since we don't care about the deploy, we just want to
// check the file generated at build time.
Expand Down
Loading