From 617e2d29bd9bceb3f4e252c176ffab1ff9f392ca Mon Sep 17 00:00:00 2001 From: Leah Date: Thu, 2 Mar 2023 17:58:24 +0100 Subject: [PATCH] Separate tabs for Errors and Warnings in error overlay (vercel/turbo#4001) --- crates/next-core/js/package.json | 2 +- .../src/overlay/internal/container/Errors.tsx | 91 +++++++++++++++---- .../internal/container/ErrorsToast.tsx | 20 +++- 3 files changed, 88 insertions(+), 25 deletions(-) diff --git a/crates/next-core/js/package.json b/crates/next-core/js/package.json index c67cbd40e1f01..1cad37d1a8ab0 100644 --- a/crates/next-core/js/package.json +++ b/crates/next-core/js/package.json @@ -12,7 +12,7 @@ "@vercel/turbopack-runtime": "latest", "anser": "^2.1.1", "css.escape": "^1.5.1", - "next": "13.1.7-canary.28", + "next": "13.1.7-canary.30", "platform": "1.3.6", "react-dom": "^18.2.0", "react": "^18.2.0", diff --git a/crates/next-core/js/src/overlay/internal/container/Errors.tsx b/crates/next-core/js/src/overlay/internal/container/Errors.tsx index ccab7a1d4be59..9cad9cb50b66d 100644 --- a/crates/next-core/js/src/overlay/internal/container/Errors.tsx +++ b/crates/next-core/js/src/overlay/internal/container/Errors.tsx @@ -166,41 +166,58 @@ function useDisplayState( } const enum TabId { - TurbopackIssues = "turbopack-issues", + TurbopackErrors = "turbopack-issues", + TurbopackWarnings = "turbopack-warnings", RuntimeErrors = "runtime-errors", } +const TAB_PRIORITY = [ + TabId.TurbopackErrors, + TabId.RuntimeErrors, + TabId.TurbopackWarnings, +]; + export function Errors({ issues, errors }: ErrorsProps) { const [readyErrors, isLoading] = useResolvedErrors(errors); - const hasIssues = issues.length !== 0; - const hasIssueWithError = issues.some((issue) => + const turbopackWarnings = issues.filter( + (issue) => !["bug", "fatal", "error"].includes(issue.severity) + ); + const turbopackErrors = issues.filter((issue) => ["bug", "fatal", "error"].includes(issue.severity) ); + const hasTurbopackWarnings = turbopackWarnings.length > 0; + const hasTurbopackErrors = turbopackErrors.length > 0; + const hasErrors = errors.length !== 0; const hasServerError = readyErrors.some((err) => ["server", "edge-server"].includes(getErrorSource(err.error) || "") ); // TODO for now it's already closable, but in future we might want to block users from using a broken app - // const isClosable = !isLoading && !hasIssueWithError && !hasServerError; + // const isClosable = !isLoading && !hasTurbopackErrors && !hasServerError; const isClosable = true; const defaultTab = - hasIssueWithError || !hasErrors - ? TabId.TurbopackIssues - : TabId.RuntimeErrors; + TAB_PRIORITY.find( + (tabId) => + ({ + [TabId.TurbopackErrors]: turbopackErrors.length > 0, + [TabId.TurbopackWarnings]: turbopackWarnings.length > 0, + [TabId.RuntimeErrors]: hasErrors, + }[tabId]) + ) ?? TabId.RuntimeErrors; const [selectedTab, setSelectedTab] = React.useState(defaultTab); React.useEffect(() => { - if (defaultTab === TabId.TurbopackIssues) { - setSelectedTab(TabId.TurbopackIssues); + if (defaultTab === TabId.TurbopackErrors) { + setSelectedTab(TabId.TurbopackErrors); } }, [defaultTab]); - const onlyHasWarnings = !hasErrors && !hasIssueWithError; + const onlyHasWarnings = !hasErrors && !hasTurbopackErrors; const [stateDisplayState, { fullscreen, minimize, hide }] = useDisplayState( onlyHasWarnings ? DisplayState.Minimized : DisplayState.Fullscreen @@ -213,7 +230,7 @@ export function Errors({ issues, errors }: ErrorsProps) { // This component shouldn't be rendered with no errors, but if it is, let's // handle it gracefully by rendering nothing. - if (!hasErrors && !hasIssues) { + if (!hasErrors && !hasTurbopackWarnings && !hasTurbopackErrors) { return null; } @@ -224,7 +241,8 @@ export function Errors({ issues, errors }: ErrorsProps) { if (displayState === DisplayState.Minimized) { return ( - {hasIssues && ( + {hasTurbopackErrors && ( + + + {turbopackErrors.length} Turbopack Error + {turbopackErrors.length > 1 ? "s" : ""} + + )} + {hasTurbopackWarnings && ( - {issues.length} Turbopack Issue{issues.length > 1 ? "s" : ""} + {turbopackWarnings.length} Turbopack Warning + {turbopackWarnings.length > 1 ? "s" : ""} )} {hasErrors && ( @@ -274,11 +317,19 @@ export function Errors({ issues, errors }: ErrorsProps) { )} - {hasIssues && ( + {hasTurbopackErrors && ( + + )} + {hasTurbopackWarnings && ( )} diff --git a/crates/next-core/js/src/overlay/internal/container/ErrorsToast.tsx b/crates/next-core/js/src/overlay/internal/container/ErrorsToast.tsx index f137c5d46aa65..0ef5c4da737de 100644 --- a/crates/next-core/js/src/overlay/internal/container/ErrorsToast.tsx +++ b/crates/next-core/js/src/overlay/internal/container/ErrorsToast.tsx @@ -4,6 +4,7 @@ import { noop as css } from "../helpers/noop-template"; export type ErrorsToastProps = { errorCount: number; + warningCount: number; severity: "error" | "warning"; onClick: () => void; onClose: () => void; @@ -11,19 +12,30 @@ export type ErrorsToastProps = { export function ErrorsToast({ errorCount, + warningCount, severity, onClick, onClose, }: ErrorsToastProps) { + let message = ""; + + if (errorCount > 0) { + message += errorCount + " " + (errorCount > 1 ? "Errors" : "Error"); + } + if (warningCount > 0) { + if (errorCount > 0) { + message += " and "; + } + + message += warningCount + " " + (warningCount > 1 ? "Warnings" : "Warning"); + } + return (
{severity == "error" && } {severity == "warning" && } - - {errorCount} {severity} - {errorCount > 1 ? "s" : ""} - + {message}