fix(BetterSettings): do not catch errors of other ui

This commit is contained in:
Vendicated 2024-05-08 23:42:04 +02:00
parent 6ad17ff7e7
commit b1cc67a860
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18

View file

@ -6,8 +6,8 @@
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common"; import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common";
@ -124,12 +124,23 @@ export default definePlugin({
} }
], ],
// This is the very outer layer of the entire ui, so we can't wrap this in an ErrorBoundary
// without possibly also catching unrelated errors of children.
//
// Thus, we sanity check webpack modules & do this really hacky try catch to hopefully prevent hard crashes if something goes wrong.
// try catch will only catch errors in the Layer function (hence why it's called as a plain function rather than a component), but
// not in children
Layer(props: LayerProps) { Layer(props: LayerProps) {
return ( try {
<ErrorBoundary fallback={() => props.children as any}> if (!FocusLock || !ComponentDispatch)
<Layer {...props} /> throw new Error("Failed to fetch some webpack modules");
</ErrorBoundary>
); return Layer(props);
} catch (e) {
new Logger("BetterSettings").error("Failed to render Layer", e);
}
return props.children;
}, },
wrapMenu(list: SettingsEntry[]) { wrapMenu(list: SettingsEntry[]) {