aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2023-05-05 16:48:35 +0200
committerVendicated <vendicated@riseup.net>2023-05-05 16:57:58 +0200
commit244d10dc9eafe5b9daf266e3a3880c888e4de540 (patch)
tree7be248df0997a861637efdeae209d7c578fac160
parentc25bc0ff4b597131ed223fd5c1a8cf75ac5282e3 (diff)
downloadVencord-244d10dc9eafe5b9daf266e3a3880c888e4de540.tar.gz
Vencord-244d10dc9eafe5b9daf266e3a3880c888e4de540.tar.bz2
Vencord-244d10dc9eafe5b9daf266e3a3880c888e4de540.zip
[skip ci] Fix handleComponentFailed spam
-rw-r--r--src/components/PluginSettings/index.tsx3
-rw-r--r--src/components/VencordSettings/Updater.tsx3
-rw-r--r--src/components/VencordSettings/index.tsx5
-rw-r--r--src/utils/index.ts2
-rw-r--r--src/utils/onlyOnce.ts29
5 files changed, 38 insertions, 4 deletions
diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx
index f3a5cd3..5a367c8 100644
--- a/src/components/PluginSettings/index.tsx
+++ b/src/components/PluginSettings/index.tsx
@@ -33,6 +33,7 @@ import Logger from "@utils/Logger";
import { Margins } from "@utils/margins";
import { classes, LazyComponent, useAwaiter } from "@utils/misc";
import { openModalLazy } from "@utils/modal";
+import { onlyOnce } from "@utils/onlyOnce";
import { Plugin } from "@utils/types";
import { findByCode, findByPropsLazy } from "@webpack";
import { Alerts, Button, Card, Forms, Parser, React, Select, Text, TextInput, Toasts, Tooltip } from "@webpack/common";
@@ -341,7 +342,7 @@ export default ErrorBoundary.wrap(function PluginSettings() {
);
}, {
message: "Failed to render the Plugin Settings. If this persists, try using the installer to reinstall!",
- onError: handleComponentFailed,
+ onError: onlyOnce(handleComponentFailed),
});
function makeDependencyList(deps: string[]) {
diff --git a/src/components/VencordSettings/Updater.tsx b/src/components/VencordSettings/Updater.tsx
index fb78394..6fec9e7 100644
--- a/src/components/VencordSettings/Updater.tsx
+++ b/src/components/VencordSettings/Updater.tsx
@@ -25,6 +25,7 @@ import { Link } from "@components/Link";
import { Margins } from "@utils/margins";
import { classes, useAwaiter } from "@utils/misc";
import { relaunch } from "@utils/native";
+import { onlyOnce } from "@utils/onlyOnce";
import { changes, checkForUpdates, getRepo, isNewer, update, updateError, UpdateLogger } from "@utils/updater";
import { Alerts, Button, Card, Forms, Parser, React, Switch, Toasts } from "@webpack/common";
@@ -250,5 +251,5 @@ function Updater() {
export default IS_WEB ? null : ErrorBoundary.wrap(Updater, {
message: "Failed to render the Updater. If this persists, try using the installer to reinstall!",
- onError: handleComponentFailed,
+ onError: onlyOnce(handleComponentFailed),
});
diff --git a/src/components/VencordSettings/index.tsx b/src/components/VencordSettings/index.tsx
index b2916c4..6d65aa1 100644
--- a/src/components/VencordSettings/index.tsx
+++ b/src/components/VencordSettings/index.tsx
@@ -22,6 +22,7 @@ import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { handleComponentFailed } from "@components/handleComponentFailed";
import { isMobile } from "@utils/misc";
+import { onlyOnce } from "@utils/onlyOnce";
import { Forms, SettingsRouter, TabBar, Text } from "@webpack/common";
import BackupRestoreTab from "./BackupRestoreTab";
@@ -86,8 +87,10 @@ function Settings(props: SettingsProps) {
</Forms.FormSection >;
}
+const onError = onlyOnce(handleComponentFailed);
+
export default function (props: SettingsProps) {
- return <ErrorBoundary onError={handleComponentFailed}>
+ return <ErrorBoundary onError={onError}>
<Settings tab={props.tab} />
</ErrorBoundary>;
}
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 98e923f..6723a70 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -25,7 +25,7 @@ export * from "./margins";
export * from "./misc";
export * as Modals from "./modal";
export * from "./onceDefined";
+export * from "./onlyOnce";
export * from "./proxyLazy";
export * from "./Queue";
export * from "./text";
-
diff --git a/src/utils/onlyOnce.ts b/src/utils/onlyOnce.ts
new file mode 100644
index 0000000..f5cb8c9
--- /dev/null
+++ b/src/utils/onlyOnce.ts
@@ -0,0 +1,29 @@
+/*
+ * Vencord, a modification for Discord's desktop app
+ * Copyright (c) 2023 Vendicated and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export function onlyOnce<F extends Function>(f: F): F {
+ let called = false;
+ let result: any;
+ return function onlyOnceWrapper(this: unknown) {
+ if (called) return result;
+
+ called = true;
+
+ return (result = f.apply(this, arguments));
+ } as unknown as F;
+}