[skip ci] Fix handleComponentFailed spam
This commit is contained in:
parent
c25bc0ff4b
commit
244d10dc9e
5 changed files with 38 additions and 4 deletions
|
@ -33,6 +33,7 @@ import Logger from "@utils/Logger";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { classes, LazyComponent, useAwaiter } from "@utils/misc";
|
import { classes, LazyComponent, useAwaiter } from "@utils/misc";
|
||||||
import { openModalLazy } from "@utils/modal";
|
import { openModalLazy } from "@utils/modal";
|
||||||
|
import { onlyOnce } from "@utils/onlyOnce";
|
||||||
import { Plugin } from "@utils/types";
|
import { Plugin } from "@utils/types";
|
||||||
import { findByCode, findByPropsLazy } from "@webpack";
|
import { findByCode, findByPropsLazy } from "@webpack";
|
||||||
import { Alerts, Button, Card, Forms, Parser, React, Select, Text, TextInput, Toasts, Tooltip } from "@webpack/common";
|
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!",
|
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[]) {
|
function makeDependencyList(deps: string[]) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { Link } from "@components/Link";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { classes, useAwaiter } from "@utils/misc";
|
import { classes, useAwaiter } from "@utils/misc";
|
||||||
import { relaunch } from "@utils/native";
|
import { relaunch } from "@utils/native";
|
||||||
|
import { onlyOnce } from "@utils/onlyOnce";
|
||||||
import { changes, checkForUpdates, getRepo, isNewer, update, updateError, UpdateLogger } from "@utils/updater";
|
import { changes, checkForUpdates, getRepo, isNewer, update, updateError, UpdateLogger } from "@utils/updater";
|
||||||
import { Alerts, Button, Card, Forms, Parser, React, Switch, Toasts } from "@webpack/common";
|
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, {
|
export default IS_WEB ? null : ErrorBoundary.wrap(Updater, {
|
||||||
message: "Failed to render the Updater. If this persists, try using the installer to reinstall!",
|
message: "Failed to render the Updater. If this persists, try using the installer to reinstall!",
|
||||||
onError: handleComponentFailed,
|
onError: onlyOnce(handleComponentFailed),
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { classNameFactory } from "@api/Styles";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { handleComponentFailed } from "@components/handleComponentFailed";
|
import { handleComponentFailed } from "@components/handleComponentFailed";
|
||||||
import { isMobile } from "@utils/misc";
|
import { isMobile } from "@utils/misc";
|
||||||
|
import { onlyOnce } from "@utils/onlyOnce";
|
||||||
import { Forms, SettingsRouter, TabBar, Text } from "@webpack/common";
|
import { Forms, SettingsRouter, TabBar, Text } from "@webpack/common";
|
||||||
|
|
||||||
import BackupRestoreTab from "./BackupRestoreTab";
|
import BackupRestoreTab from "./BackupRestoreTab";
|
||||||
|
@ -86,8 +87,10 @@ function Settings(props: SettingsProps) {
|
||||||
</Forms.FormSection >;
|
</Forms.FormSection >;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onError = onlyOnce(handleComponentFailed);
|
||||||
|
|
||||||
export default function (props: SettingsProps) {
|
export default function (props: SettingsProps) {
|
||||||
return <ErrorBoundary onError={handleComponentFailed}>
|
return <ErrorBoundary onError={onError}>
|
||||||
<Settings tab={props.tab} />
|
<Settings tab={props.tab} />
|
||||||
</ErrorBoundary>;
|
</ErrorBoundary>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export * from "./margins";
|
||||||
export * from "./misc";
|
export * from "./misc";
|
||||||
export * as Modals from "./modal";
|
export * as Modals from "./modal";
|
||||||
export * from "./onceDefined";
|
export * from "./onceDefined";
|
||||||
|
export * from "./onlyOnce";
|
||||||
export * from "./proxyLazy";
|
export * from "./proxyLazy";
|
||||||
export * from "./Queue";
|
export * from "./Queue";
|
||||||
export * from "./text";
|
export * from "./text";
|
||||||
|
|
||||||
|
|
29
src/utils/onlyOnce.ts
Normal file
29
src/utils/onlyOnce.ts
Normal file
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in a new issue