Fix wrongfully logging LazyComponent factory failed

This commit is contained in:
Nuckyz 2024-05-05 02:52:41 -03:00
parent 17397dbe08
commit 8d31330d3e
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 6 additions and 8 deletions

View file

@ -9,16 +9,16 @@ export function makeLazy<T>(factory: () => T, attempts = 5): () => T {
let cache: T;
const getter = () => {
if (!cache && attempts > tries++) {
if (!cache && attempts > tries) {
cache = factory();
if (!cache && attempts === tries) {
if (!cache && attempts === ++tries) {
console.error(`Lazy factory failed:\n\n${factory}`);
}
}
return cache;
};
getter.$$vencordLazyFailed = () => tries >= attempts;
getter.$$vencordLazyFailed = () => tries === attempts;
return getter;
}

View file

@ -23,15 +23,13 @@ export function LazyComponent<T extends object = any>(factory: () => React.Compo
let Component = (() => {
console.error(`LazyComponent factory failed:\n\n${factory}`);
return NoopComponent;
})() as React.ComponentType<T>;
return null;
}) as React.ComponentType<T>;
// @ts-ignore
if (!get.$$vencordLazyFailed()) {
const result = get();
if (result != null) {
Component = result;
}
if (result != null) Component = result;
}
return <Component {...props} />;