Unverified Commit 588bf8ee authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

improve turbopack error overlay (#47132)

### What?

Improve the UX of the error overlay

### Why?

* error overlay doesn't reopen when closed, but new error appear
* error overlay shows non-actionable warnings in node_modules
* error overlay shows unrelevant errors in node_modules

### How?

* low priority for errors in node_modules
* hide node_modules warnings
* open error overlay on new error
* Also updated the files I touched to the next.js prettier format


fixes WEB-712
fixes WEB-713
fixes WEB-714
fixes WEB-727
Co-authored-by: 's avatarLeah <8845940+ForsakenHarmony@users.noreply.github.com>
parent 26a17fac
import * as React from "react"; import * as React from 'react'
import { noop as css } from "../../helpers/noop-template"; import { noop as css } from '../../helpers/noop-template'
import { clsx } from "../../helpers/clsx"; import { clsx } from '../../helpers/clsx'
import { TabList } from "../Tabs"; import { TabList } from '../Tabs'
export type DialogHeaderTabListProps = { export type DialogHeaderTabListProps = {
className?: string; className?: string
children: React.ReactNode; children: React.ReactNode
}; }
export function DialogHeaderTabList({ export function DialogHeaderTabList({
className, className,
children, children,
}: DialogHeaderTabListProps) { }: DialogHeaderTabListProps) {
return ( return (
<TabList className={clsx("dialog-header-tab-list", className)}> <TabList className={clsx('dialog-header-tab-list', className)}>
{children} {children}
</TabList> </TabList>
); )
} }
export const styles = css` export const styles = css`
...@@ -46,7 +46,6 @@ export const styles = css` ...@@ -46,7 +46,6 @@ export const styles = css`
padding-bottom: calc(var(--local-padding) - var(--size-border)); padding-bottom: calc(var(--local-padding) - var(--size-border));
height: 100%; height: 100%;
min-width: 250px;
border-top: none; border-top: none;
border-bottom: var(--border); border-bottom: var(--border);
...@@ -69,17 +68,17 @@ export const styles = css` ...@@ -69,17 +68,17 @@ export const styles = css`
border-top: var(--size-border-double) solid transparent; border-top: var(--size-border-double) solid transparent;
content: " "; content: ' ';
} }
.dialog-header-tab-list > .tab:hover { .dialog-header-tab-list > .tab:hover {
background-color: var(--color-bg-secondary-hover); background-color: var(--color-bg-secondary-hover);
} }
.dialog-header-tab-list > .tab[aria-selected="true"] { .dialog-header-tab-list > .tab[aria-selected='true'] {
color: var(--color-text); color: var(--color-text);
background-color: var(--color-bg); background-color: var(--color-bg);
border-bottom-color: transparent; border-bottom-color: transparent;
} }
`; `
import { noop as css } from "../../helpers/noop-template"; import { noop as css } from '../../helpers/noop-template'
const styles = css` const styles = css`
.dialog-left-right {
white-space: nowrap;
}
.dialog-left-right > button { .dialog-left-right > button {
--bg-alpha: 0.1; --bg-alpha: 0.1;
--fg-alpha: 1; --fg-alpha: 1;
...@@ -21,11 +25,11 @@ const styles = css` ...@@ -21,11 +25,11 @@ const styles = css`
transition: background-color 0.25s ease; transition: background-color 0.25s ease;
} }
.dialog-left-right[data-severity="error"] > button { .dialog-left-right[data-severity='error'] > button {
--color-base: var(--color-error-bright-hsl); --color-base: var(--color-error-bright-hsl);
} }
.dialog-left-right[data-severity="warning"] > button { .dialog-left-right[data-severity='warning'] > button {
--color-base: var(--color-warning-bright-hsl); --color-base: var(--color-warning-bright-hsl);
} }
...@@ -52,6 +56,6 @@ const styles = css` ...@@ -52,6 +56,6 @@ const styles = css`
width: auto; width: auto;
height: var(--size-icon-small); height: var(--size-icon-small);
} }
`; `
export { styles }; export { styles }
import { noop as css } from "../../helpers/noop-template"; import { noop as css } from '../../helpers/noop-template'
const styles = css` const styles = css`
.terminal { .terminal {
...@@ -28,10 +28,11 @@ const styles = css` ...@@ -28,10 +28,11 @@ const styles = css`
} }
.terminal pre { .terminal pre {
width: 100%;
white-space: pre-wrap; white-space: pre-wrap;
word-break: break-word; word-break: break-word;
overflow-y: scroll; overflow-y: scroll;
} }
`; `
export { styles }; export { styles }
import { Toast } from "../components/Toast"; import { Toast } from '../components/Toast'
import { AlertOctagon, AlertTriangle, CloseIcon } from "../icons"; import { AlertOctagon, AlertTriangle, CloseIcon } from '../icons'
import { noop as css } from "../helpers/noop-template"; import { noop as css } from '../helpers/noop-template'
export type ErrorsToastProps = { export type ErrorsToastProps = {
errorCount: number; errorCount: number
warningCount: number; warningCount: number
severity: "error" | "warning"; severity: 'error' | 'warning'
onClick: () => void; onClick: () => void
onClose: () => void; onClose: () => void
}; }
export function ErrorsToast({ export function ErrorsToast({
errorCount, errorCount,
...@@ -17,42 +17,51 @@ export function ErrorsToast({ ...@@ -17,42 +17,51 @@ export function ErrorsToast({
onClick, onClick,
onClose, onClose,
}: ErrorsToastProps) { }: ErrorsToastProps) {
let message = ""; let message = ''
if (errorCount > 0) { if (errorCount > 0) {
message += errorCount + " " + (errorCount > 1 ? "Errors" : "Error"); message += errorCount + ' ' + (errorCount > 1 ? 'Errors' : 'Error')
} }
if (warningCount > 0) { if (warningCount > 0) {
if (errorCount > 0) { if (errorCount > 0) {
message += " and "; message += ' and '
} }
message += warningCount + " " + (warningCount > 1 ? "Warnings" : "Warning"); message += warningCount + ' ' + (warningCount > 1 ? 'Warnings' : 'Warning')
} }
return ( return (
<Toast className="toast-errors" onClick={onClick} data-severity={severity}> <Toast
className="toast-errors"
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
onClick()
}}
data-severity={severity}
>
<div className="toast-errors-body"> <div className="toast-errors-body">
{severity == "error" && <AlertOctagon />} {severity == 'error' && <AlertOctagon />}
{severity == "warning" && <AlertTriangle />} {severity == 'warning' && <AlertTriangle />}
<span>{message}</span> <span>{message}</span>
<button <button
data-toast-errors-hide-button data-toast-errors-hide-button
className="toast-errors-hide-button" className="toast-errors-hide-button"
type="button" type="button"
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.preventDefault()
onClose(); e.stopPropagation()
onClose()
}} }}
aria-label={ aria-label={
{ error: "Hide Errors", warning: "Hide Warnings" }[severity] { error: 'Hide Errors', warning: 'Hide Warnings' }[severity]
} }
> >
<CloseIcon /> <CloseIcon />
</button> </button>
</div> </div>
</Toast> </Toast>
); )
} }
export const styles = css` export const styles = css`
...@@ -91,4 +100,4 @@ export const styles = css` ...@@ -91,4 +100,4 @@ export const styles = css`
.toast-errors-hide-button:hover { .toast-errors-hide-button:hover {
opacity: 1; opacity: 1;
} }
`; `
import { Issue } from "@vercel/turbopack-runtime/types/protocol"; import { Issue } from '@vercel/turbopack-runtime/types/protocol'
import { LeftRightDialogHeader } from "../components/LeftRightDialogHeader"; import { LeftRightDialogHeader } from '../components/LeftRightDialogHeader'
import { DialogBody, DialogBodyProps } from "../components/Dialog"; import { DialogBody, DialogBodyProps } from '../components/Dialog'
import { Terminal } from "../components/Terminal"; import { Terminal } from '../components/Terminal'
import { noop as css } from "../helpers/noop-template"; import { noop as css } from '../helpers/noop-template'
import { clsx } from "../helpers/clsx"; import { clsx } from '../helpers/clsx'
import { usePagination } from "../hooks/usePagination"; import { usePagination } from '../hooks/usePagination'
type TurbopackIssuesDialogBodyProps = { type TurbopackIssuesDialogBodyProps = {
issues: Issue[]; items: Issue[]
"data-hidden"?: boolean; message: string
}; severity: 'error' | 'warning'
'data-hidden'?: boolean
}
export function TurbopackIssuesDialogBody({ export function TurbopackIssuesDialogBody({
issues, items: issues,
"data-hidden": hidden = false, message,
severity,
'data-hidden': hidden = false,
className, className,
...rest ...rest
}: TurbopackIssuesDialogBodyProps & Omit<DialogBodyProps, "children">) { }: TurbopackIssuesDialogBodyProps & Omit<DialogBodyProps, 'children'>) {
const [activeIssue, { previous, next }, activeIdx] = usePagination(issues); const [activeIssue, { previous, next }, activeIdx] = usePagination(issues)
const hasIssues = issues.length > 0; const hasIssues = issues.length > 0
const hasIssueWithError = issues.some((issue) =>
["bug", "fatal", "error"].includes(issue.severity)
);
if (!hasIssues || !activeIssue) { if (!hasIssues || !activeIssue) {
return null; return null
} }
const activeIssueIsError = ["bug", "fatal", "error"].includes( const activeIssueIsError = ['bug', 'fatal', 'error'].includes(
activeIssue.severity activeIssue.severity
); )
return ( return (
<DialogBody <DialogBody
{...rest} {...rest}
data-hidden={hidden} data-hidden={hidden}
className={clsx("issues-body", className)} className={clsx('issues-body', className)}
> >
<div className="title-pagination"> <div className="title-pagination">
<h1 id="nextjs__container_errors_label"> <h1 id="nextjs__container_errors_label">{message}</h1>
{hasIssueWithError
? "Turbopack failed to compile"
: "Turbopack compiled with warnings"}
</h1>
<LeftRightDialogHeader <LeftRightDialogHeader
hidden={hidden} hidden={hidden}
previous={activeIdx > 0 ? previous : null} previous={activeIdx > 0 ? previous : null}
next={activeIdx < issues.length - 1 ? next : null} next={activeIdx < issues.length - 1 ? next : null}
severity={activeIssueIsError ? "error" : "warning"} severity={severity}
> >
<small> <small>
<span>{activeIdx + 1}</span> of <span>{issues.length}</span> <span>{activeIdx + 1}</span> of <span>{issues.length}</span>
...@@ -59,7 +56,7 @@ export function TurbopackIssuesDialogBody({ ...@@ -59,7 +56,7 @@ export function TurbopackIssuesDialogBody({
<h2 <h2
id="nextjs__container_errors_desc" id="nextjs__container_errors_desc"
data-severity={activeIssueIsError ? "error" : "warning"} data-severity={activeIssueIsError ? 'error' : 'warning'}
> >
{activeIssue.title} {activeIssue.title}
</h2> </h2>
...@@ -76,7 +73,7 @@ export function TurbopackIssuesDialogBody({ ...@@ -76,7 +73,7 @@ export function TurbopackIssuesDialogBody({
</footer> </footer>
)} )}
</DialogBody> </DialogBody>
); )
} }
export const styles = css` export const styles = css`
...@@ -95,4 +92,4 @@ export const styles = css` ...@@ -95,4 +92,4 @@ export const styles = css`
.issues-body > footer > small { .issues-body > footer > small {
color: #757575; color: #757575;
} }
`; `
import { TYPE_UNHANDLED_ERROR, TYPE_UNHANDLED_REJECTION } from "../bus"; import { TYPE_UNHANDLED_ERROR, TYPE_UNHANDLED_REJECTION } from '../bus'
import { SupportedErrorEvent } from "../container/Errors"; import { SupportedErrorEvent } from '../container/Errors'
import { getErrorSource } from "./nodeStackFrames"; import { getErrorSource } from './nodeStackFrames'
import { getOriginalStackFrames, OriginalStackFrame } from "./stack-frame"; import { getOriginalStackFrames, OriginalStackFrame } from './stack-frame'
export type ReadyRuntimeError = { export type ReadyRuntimeError = {
id: number; id: number
runtime: true; runtime: true
error: Error; error: Error
frames: OriginalStackFrame[]; frames: OriginalStackFrame[]
}; }
export async function getErrorByType( export async function getErrorByType(
ev: SupportedErrorEvent ev: SupportedErrorEvent
): Promise<ReadyRuntimeError> { ): Promise<ReadyRuntimeError> {
const { id, event } = ev; const { id, event } = ev
switch (event.type) { switch (event.type) {
case TYPE_UNHANDLED_ERROR: case TYPE_UNHANDLED_ERROR:
case TYPE_UNHANDLED_REJECTION: { case TYPE_UNHANDLED_REJECTION: {
...@@ -27,12 +27,42 @@ export async function getErrorByType( ...@@ -27,12 +27,42 @@ export async function getErrorByType(
getErrorSource(event.reason), getErrorSource(event.reason),
event.reason.toString() event.reason.toString()
), ),
}; }
}
default: {
break
}
}
throw new Error('type system invariant violation')
}
export function getUnresolvedErrorByType(
ev: SupportedErrorEvent
): ReadyRuntimeError {
const { id, event } = ev
switch (event.type) {
case TYPE_UNHANDLED_ERROR:
case TYPE_UNHANDLED_REJECTION: {
return {
id,
runtime: true,
error: event.reason,
frames: event.frames.map((frame) => ({
error: true,
reason: 'unresolved',
external: false,
expanded: false,
sourceStackFrame: frame,
originalStackFrame: null,
originalCodeFrame: null,
})),
}
} }
default: { default: {
break; break
} }
} }
throw new Error("type system invariant violation"); throw new Error('type system invariant violation')
} }
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