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