Skip to content

Commit

Permalink
Fix wrongfully logging LazyComponent factory failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckyz committed May 5, 2024
1 parent 17397db commit 8d31330
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/utils/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions src/utils/lazyReact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} />;
Expand Down

0 comments on commit 8d31330

Please sign in to comment.