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

feat: Opt-out Error page from dark scheme color #36951

Merged
merged 8 commits into from
May 22, 2022
11 changes: 9 additions & 2 deletions packages/next/pages/_error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const statusCodes: { [code: number]: string } = {
export type ErrorProps = {
statusCode: number
title?: string
withDarkMode?: boolean
}

function _getInitialProps({
Expand All @@ -33,7 +34,7 @@ export default class Error<P = {}> extends React.Component<P & ErrorProps> {
static origGetInitialProps = _getInitialProps

render() {
const { statusCode } = this.props
const { statusCode, withDarkMode = true } = this.props
const title =
this.props.title ||
statusCodes[statusCode] ||
Expand All @@ -56,14 +57,20 @@ export default class Error<P = {}> extends React.Component<P & ErrorProps> {
.next-error-h1 {
border-right: 1px solid rgba(0, 0, 0, .3);
icyJoseph marked this conversation as resolved.
Show resolved Hide resolved
}
@media (prefers-color-scheme: dark) {

${
withDarkMode
? `@media (prefers-color-scheme: dark) {
body { color: #fff; background: #000; }
.next-error-h1 {
border-right: 1px solid rgba(255, 255, 255, .3);
}
}`
: ''
}`,
}}
/>

{statusCode ? (
<h1 className="next-error-h1" style={styles.h1}>
{statusCode}
Expand Down