Fix wrongfully logging LazyComponent factory failed
This commit is contained in:
parent
17397dbe08
commit
8d31330d3e
|
@ -9,16 +9,16 @@ export function makeLazy<T>(factory: () => T, attempts = 5): () => T {
|
||||||
let cache: T;
|
let cache: T;
|
||||||
|
|
||||||
const getter = () => {
|
const getter = () => {
|
||||||
if (!cache && attempts > tries++) {
|
if (!cache && attempts > tries) {
|
||||||
cache = factory();
|
cache = factory();
|
||||||
if (!cache && attempts === tries) {
|
if (!cache && attempts === ++tries) {
|
||||||
console.error(`Lazy factory failed:\n\n${factory}`);
|
console.error(`Lazy factory failed:\n\n${factory}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cache;
|
return cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
getter.$$vencordLazyFailed = () => tries >= attempts;
|
getter.$$vencordLazyFailed = () => tries === attempts;
|
||||||
|
|
||||||
return getter;
|
return getter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,13 @@ export function LazyComponent<T extends object = any>(factory: () => React.Compo
|
||||||
let Component = (() => {
|
let Component = (() => {
|
||||||
console.error(`LazyComponent factory failed:\n\n${factory}`);
|
console.error(`LazyComponent factory failed:\n\n${factory}`);
|
||||||
|
|
||||||
return NoopComponent;
|
return null;
|
||||||
})() as React.ComponentType<T>;
|
}) as React.ComponentType<T>;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!get.$$vencordLazyFailed()) {
|
if (!get.$$vencordLazyFailed()) {
|
||||||
const result = get();
|
const result = get();
|
||||||
if (result != null) {
|
if (result != null) Component = result;
|
||||||
Component = result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Component {...props} />;
|
return <Component {...props} />;
|
||||||
|
|
Loading…
Reference in a new issue