diff --git a/packages/next/src/lib/verifyRootLayout.ts b/packages/next/src/lib/verifyRootLayout.ts index 329ec3b981822..008316ec0ec2a 100644 --- a/packages/next/src/lib/verifyRootLayout.ts +++ b/packages/next/src/lib/verifyRootLayout.ts @@ -18,14 +18,18 @@ const glob = (cwd: string, pattern: string): Promise => { function getRootLayout(isTs: boolean) { if (isTs) { - return `export default function RootLayout({ + return `export const metadata = { + title: 'Next.js', + description: 'Generated by Next.js', +} + +export default function RootLayout({ children, }: { children: React.ReactNode }) { return ( - - + {children} ) @@ -33,10 +37,14 @@ function getRootLayout(isTs: boolean) { ` } - return `export default function RootLayout({ children }) { - return ( - - + return `export const metadata = { + title: 'Next.js', + description: 'Generated by Next.js', +} + +export default function RootLayout({ children }) { + return ( + {children} ) @@ -44,19 +52,6 @@ function getRootLayout(isTs: boolean) { ` } -function getHead() { - return `export default function Head() { - return ( - <> - - - - - ) -} -` -} - export async function verifyRootLayout({ dir, appDir, @@ -120,19 +115,6 @@ export async function verifyRootLayout({ `layout.${hasTsConfig ? 'tsx' : 'js'}` ) await fs.writeFile(rootLayoutPath, getRootLayout(hasTsConfig)) - const headPath = path.join( - appDir, - availableDir, - `head.${hasTsConfig ? 'tsx' : 'js'}` - ) - const hasHead = await fs.access(headPath).then( - () => true, - () => false - ) - - if (!hasHead) { - await fs.writeFile(headPath, getHead()) - } console.log( chalk.green( @@ -140,11 +122,7 @@ export async function verifyRootLayout({ `app/${normalizedPagePath}` )} did not have a root layout. We created ${chalk.bold( `app${rootLayoutPath.replace(appDir, '')}` - )}${ - !hasHead - ? ` and ${chalk.bold(`app${headPath.replace(appDir, '')}`)}` - : '' - } for you.` + )} for you.` ) + '\n' ) diff --git a/test/e2e/app-dir/create-root-layout/create-root-layout.test.ts b/test/e2e/app-dir/create-root-layout/create-root-layout.test.ts index fdb763a3a4502..12fcec912436e 100644 --- a/test/e2e/app-dir/create-root-layout/create-root-layout.test.ts +++ b/test/e2e/app-dir/create-root-layout/create-root-layout.test.ts @@ -46,29 +46,20 @@ describe('app-dir create root layout', () => { /did not have a root layout/ ) expect(stripAnsi(next.cliOutput.slice(outputIndex))).toMatch( - 'Your page app/route/page.js did not have a root layout. We created app/layout.js and app/head.js for you.' + 'Your page app/route/page.js did not have a root layout. We created app/layout.js for you.' ) expect(await next.readFile('app/layout.js')).toMatchInlineSnapshot(` - "export default function RootLayout({ children }) { - return ( - - - {children} - - ) - } - " - `) - - expect(await next.readFile('app/head.js')).toMatchInlineSnapshot(` - "export default function Head() { - return ( - <> - - - - + "export const metadata = { + title: 'Next.js', + description: 'Generated by Next.js', + } + + export default function RootLayout({ children }) { + return ( + + {children} + ) } " @@ -106,31 +97,21 @@ describe('app-dir create root layout', () => { /did not have a root layout/ ) expect(stripAnsi(next.cliOutput.slice(outputIndex))).toInclude( - 'Your page app/(group)/page.js did not have a root layout. We created app/(group)/layout.js and app/(group)/head.js for you.' + 'Your page app/(group)/page.js did not have a root layout. We created app/(group)/layout.js for you.' ) expect(await next.readFile('app/(group)/layout.js')) .toMatchInlineSnapshot(` - "export default function RootLayout({ children }) { - return ( - - - {children} - - ) - } - " - `) - - expect(await next.readFile('app/(group)/head.js')) - .toMatchInlineSnapshot(` - "export default function Head() { - return ( - <> - - - - + "export const metadata = { + title: 'Next.js', + description: 'Generated by Next.js', + } + + export default function RootLayout({ children }) { + return ( + + {children} + ) } " @@ -168,31 +149,21 @@ describe('app-dir create root layout', () => { /did not have a root layout/ ) expect(stripAnsi(next.cliOutput.slice(outputIndex))).toInclude( - 'Your page app/(group)/route/second/inner/page.js did not have a root layout. We created app/(group)/route/second/layout.js and app/(group)/route/second/head.js for you.' + 'Your page app/(group)/route/second/inner/page.js did not have a root layout. We created app/(group)/route/second/layout.js for you.' ) expect(await next.readFile('app/(group)/route/second/layout.js')) .toMatchInlineSnapshot(` - "export default function RootLayout({ children }) { - return ( - - - {children} - - ) - } - " - `) - - expect(await next.readFile('app/(group)/route/second/head.js')) - .toMatchInlineSnapshot(` - "export default function Head() { - return ( - <> - - - - + "export const metadata = { + title: 'Next.js', + description: 'Generated by Next.js', + } + + export default function RootLayout({ children }) { + return ( + + {children} + ) } " @@ -229,33 +200,24 @@ describe('app-dir create root layout', () => { /did not have a root layout/ ) expect(stripAnsi(next.cliOutput.slice(outputIndex))).toInclude( - 'Your page app/page.tsx did not have a root layout. We created app/layout.tsx and app/head.tsx for you.' + 'Your page app/page.tsx did not have a root layout. We created app/layout.tsx for you.' ) expect(await next.readFile('app/layout.tsx')).toMatchInlineSnapshot(` - "export default function RootLayout({ - children, - }: { - children: React.ReactNode - }) { - return ( - - - {children} - - ) - } - " - `) + "export const metadata = { + title: 'Next.js', + description: 'Generated by Next.js', + } - expect(await next.readFile('app/head.tsx')).toMatchInlineSnapshot(` - "export default function Head() { + export default function RootLayout({ + children, + }: { + children: React.ReactNode + }) { return ( - <> - - - - + + {children} + ) } "