Fix Next.js build: Add required HTML structure to root layout#238
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
371774c
into
copilot/restructure-website-docs
There was a problem hiding this comment.
Pull request overview
This PR fixes a Next.js 16 TypeScript build error by adding the required HTML document structure (<html> and <body> tags) to the root layout. Next.js 16 requires root layouts to return a complete HTML document rather than just returning children directly.
Changes:
- Added
<html>and<body>wrapper elements toapps/docs/app/layout.tsx - Included
suppressHydrationWarningattribute on the html tag - Set language attribute to "en" on the html element
| return ( | ||
| <html lang="en" suppressHydrationWarning> | ||
| <body>{children}</body> | ||
| </html> | ||
| ); | ||
| } |
There was a problem hiding this comment.
This change creates nested HTML structure, which is invalid. Both the root layout (app/layout.tsx) and the child layout (app/[lang]/layout.tsx) now have html and body tags. In Next.js App Router, only the root layout should contain these tags. The [lang]/layout.tsx should be updated to remove its html and body tags and only wrap children with the RootProvider component. This will result in nested HTML like: html > body > html > body, which browsers will not render correctly.
| return ( | |
| <html lang="en" suppressHydrationWarning> | |
| <body>{children}</body> | |
| </html> | |
| ); | |
| } | |
| return children; | |
| } |
Next.js build failed with TypeScript error: root layout returned
ReactNodeinstead of expected HTML document structure.Changes
<html>and<body>tags inapps/docs/app/layout.tsxNext.js 16 requires root layouts to return complete HTML structure. The previous implementation returned children directly, which violated the framework's type constraints:
The language-specific layout in
app/[lang]/layout.tsxalready had proper HTML structure. Middleware continues handling locale routing unchanged.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.