Merge branch 'dev' into immediate-finds

This commit is contained in:
Nuckyz 2024-05-08 18:47:22 -03:00
commit 20b071aa2d
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 20 additions and 7 deletions

View file

@ -6,8 +6,10 @@
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 { proxyInnerValue } from "@utils/proxyInner";
import { NoopComponent } from "@utils/react";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByProps } from "@webpack"; import { findByProps } from "@webpack";
import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common"; import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common";
@ -124,12 +126,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 === NoopComponent || FocusLock[proxyInnerValue] == null || ComponentDispatch[proxyInnerValue] == null)
<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[]) {

View file

@ -93,7 +93,7 @@ export default definePlugin({
shouldAttemptRecover = false; shouldAttemptRecover = false;
// This is enough to avoid a crash loop // This is enough to avoid a crash loop
setTimeout(() => shouldAttemptRecover = true, 500); setTimeout(() => shouldAttemptRecover = true, 1000);
} catch { } } catch { }
try { try {