Unverified Commit 754fadac authored by Shu Ding's avatar Shu Ding Committed by GitHub

Revert "fix(next): global not-found not working on multi-root layouts" (#64601)

Reverts #63053.

Closes NEXT-3135
parent bc1d1907
......@@ -200,10 +200,9 @@ async function createTreeCodeFromPath(
const isDefaultNotFound = isAppBuiltinNotFoundPage(pagePath)
const appDirPrefix = isDefaultNotFound ? APP_DIR_ALIAS : splittedPath[0]
const rootNotFound = await resolver(
const hasRootNotFound = await resolver(
`${appDirPrefix}/${FILE_TYPES['not-found']}`
)
const hasRootNotFound = Boolean(rootNotFound)
const pages: string[] = []
let rootLayout: string | undefined
......@@ -383,8 +382,7 @@ async function createTreeCodeFromPath(
)?.[1]
rootLayout = layoutPath
const isRootNotFound = hasRootNotFound && isRootLayer && isNotFoundRoute
if ((isRootNotFound || isDefaultNotFound) && !layoutPath) {
if (isDefaultNotFound && !layoutPath && !rootLayout) {
rootLayout = defaultLayoutPath
definedFilePaths.push(['layout', rootLayout])
}
......
export default function NotFound() {
return <p>not found</p>
}
import { notFound } from 'next/navigation'
export default function Page() {
notFound()
return <p>hello world</p>
}
import { nextTestSetup } from 'e2e-utils'
describe('root-not-found-missing-root-layout', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should not conflict with generated layout on dev server', async () => {
const browser = await next.browser('/')
// eslint-disable-next-line jest/no-standalone-expect
expect(await browser.elementByCss('p').text()).toBe('not found')
})
})
export default function MainRoot({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function MaiNotFound() {
return <h1>Main Not Found</h1>
}
import { notFound } from 'next/navigation'
export default function Main() {
notFound()
return <h1>Main</h1>
}
export default function SubRoot({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function SubNotFound() {
return <h1>Sub Not Found</h1>
}
import { notFound } from 'next/navigation'
export default function Sub() {
notFound()
return <h1>Sub</h1>
}
export default function RootNotFound() {
return <h1>Root Not Found</h1>
}
import { nextTestSetup } from 'e2e-utils'
describe('not-found-multi-root-layout', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should render main not-found', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('h1').text()).toBe('Main Not Found')
})
it('should render sub not-found', async () => {
const browser = await next.browser('/sub')
expect(await browser.elementByCss('h1').text()).toBe('Sub Not Found')
})
it('should render root not-found for uncaught routes', async () => {
const browser = await next.browser('/404')
expect(await browser.elementByCss('h1').text()).toBe('Root Not Found')
})
})
......@@ -2164,18 +2164,6 @@
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/not-found/multi-root-layout/index.test.ts": {
"passed": [
"not-found-multi-root-layout should render main not-found",
"not-found-multi-root-layout should render sub not-found"
],
"failed": [
"not-found-multi-root-layout should render root not-found for uncaught routes"
],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/pages-to-app-routing/pages-to-app-routing.test.ts": {
"passed": ["pages-to-app-routing should work using browser"],
"failed": [],
......@@ -1531,15 +1531,6 @@
"flakey": [],
"runtimeError": false
},
"test/development/app-dir/root-not-found-missing-root-layout/index.test.ts": {
"passed": [],
"failed": [
"root-not-found-missing-root-layout should not conflict with generated layout on dev server"
],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/development/app-dir/strict-mode-enabled-by-default/strict-mode-enabled-by-default.test.ts": {
"passed": ["Strict Mode enabled by default should work using browser"],
"failed": [],
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment