Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move root layout validation (#41338)
Moves where the validation is made to make sure the error reaches the client. Tests that an error overlay is shown on the client. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) Co-authored-by: JJ Kasper <jj@jjsweb.site>
- Loading branch information
Showing
12 changed files
with
219 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
72 changes: 72 additions & 0 deletions
72
packages/next/client/components/react-dev-overlay/internal/container/RootLayoutError.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from 'react' | ||
import { | ||
Dialog, | ||
DialogBody, | ||
DialogContent, | ||
DialogHeader, | ||
} from '../components/Dialog' | ||
import { Overlay } from '../components/Overlay' | ||
import { Terminal } from '../components/Terminal' | ||
import { noop as css } from '../helpers/noop-template' | ||
|
||
export type RootLayoutErrorProps = { missingTags: string[] } | ||
|
||
export const RootLayoutError: React.FC<RootLayoutErrorProps> = | ||
function BuildError({ missingTags }) { | ||
const message = | ||
'Please make sure to include the following tags in your root layout: <html>, <head>, <body>.\n\n' + | ||
`Missing required root layout tag${ | ||
missingTags.length === 1 ? '' : 's' | ||
}: ` + | ||
missingTags.join(', ') | ||
|
||
const noop = React.useCallback(() => {}, []) | ||
return ( | ||
<Overlay fixed> | ||
<Dialog | ||
type="error" | ||
aria-labelledby="nextjs__container_root_layout_error_label" | ||
aria-describedby="nextjs__container_root_layout_error_desc" | ||
onClose={noop} | ||
> | ||
<DialogContent> | ||
<DialogHeader className="nextjs-container-root-layout-error-header"> | ||
<h4 id="nextjs__container_root_layout_error_label"> | ||
Root layout error | ||
</h4> | ||
</DialogHeader> | ||
<DialogBody className="nextjs-container-root-layout-error-body"> | ||
<Terminal content={message} /> | ||
<footer> | ||
<p id="nextjs__container_root_layout_error_desc"> | ||
<small> | ||
This error occurred during the build process and can only be | ||
dismissed by fixing the error. | ||
</small> | ||
</p> | ||
</footer> | ||
</DialogBody> | ||
</DialogContent> | ||
</Dialog> | ||
</Overlay> | ||
) | ||
} | ||
|
||
export const styles = css` | ||
.nextjs-container-root-layout-error-header > h4 { | ||
line-height: 1.5; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
.nextjs-container-root-layout-error-body footer { | ||
margin-top: var(--size-gap); | ||
} | ||
.nextjs-container-root-layout-error-body footer p { | ||
margin: 0; | ||
} | ||
.nextjs-container-root-layout-error-body small { | ||
color: #757575; | ||
} | ||
` |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.