From 128ee41252b1bf9c3e415ec94ce26d5dc3e7c7ee Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 25 Feb 2023 19:10:01 +0100 Subject: [PATCH] ErrorBoundary: Do not use any Discord components to be more robust --- src/components/ErrorBoundary.tsx | 9 ++++----- src/components/ErrorCard.css | 7 +++++++ src/components/ErrorCard.tsx | 23 +++++++---------------- src/utils/misc.tsx | 4 ++-- 4 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 src/components/ErrorCard.css diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index a13640e1..1eb2eb8d 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -17,8 +17,9 @@ */ import Logger from "@utils/Logger"; +import { Margins } from "@utils/margins"; import { LazyComponent } from "@utils/misc"; -import { Margins, React } from "@webpack/common"; +import { React } from "@webpack/common"; import { ErrorCard } from "./ErrorCard"; @@ -84,15 +85,13 @@ const ErrorBoundary = LazyComponent(() => { const msg = this.props.message || "An error occurred while rendering this Component. More info can be found below and in your console."; return ( - +

Oh no!

{msg}

{this.state.message} {!!this.state.stack && ( -
+                            
                                 {this.state.stack}
                             
)} diff --git a/src/components/ErrorCard.css b/src/components/ErrorCard.css new file mode 100644 index 00000000..5146aa03 --- /dev/null +++ b/src/components/ErrorCard.css @@ -0,0 +1,7 @@ +.vc-error-card { + padding: 2em; + background-color: #e7828430; + border: 1px solid #e78284; + border-radius: 5px; + color: var(--text-normal, white); +} diff --git a/src/components/ErrorCard.tsx b/src/components/ErrorCard.tsx index e749ea4b..7ce8cad1 100644 --- a/src/components/ErrorCard.tsx +++ b/src/components/ErrorCard.tsx @@ -16,24 +16,15 @@ * along with this program. If not, see . */ -import { Card } from "@webpack/common"; +import "./ErrorCard.css"; -interface Props { - style?: React.CSSProperties; - className?: string; -} -export function ErrorCard(props: React.PropsWithChildren) { +import { classes } from "@utils/misc"; +import type { HTMLProps } from "react"; + +export function ErrorCard(props: React.PropsWithChildren>) { return ( - +
{props.children} - +
); } diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx index a41ab673..b64dff9a 100644 --- a/src/utils/misc.tsx +++ b/src/utils/misc.tsx @@ -141,8 +141,8 @@ export function humanFriendlyJoin(elements: any[], mapper: (e: any) => string = * Calls .join(" ") on the arguments * classes("one", "two") => "one two" */ -export function classes(...classes: string[]) { - return classes.filter(c => typeof c === "string").join(" "); +export function classes(...classes: Array) { + return classes.filter(Boolean).join(" "); } /**