From f39f16d34bd12a19c4c06b2ac4d7ba4010c1dcef Mon Sep 17 00:00:00 2001 From: V Date: Thu, 23 Nov 2023 06:43:22 +0100 Subject: [PATCH] fix circular import bricking browser version --- src/utils/lazyReact.tsx | 23 +++++++++++++++++++++++ src/utils/react.tsx | 17 ++--------------- src/webpack/webpack.ts | 5 +---- 3 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 src/utils/lazyReact.tsx diff --git a/src/utils/lazyReact.tsx b/src/utils/lazyReact.tsx new file mode 100644 index 00000000..abd300a9 --- /dev/null +++ b/src/utils/lazyReact.tsx @@ -0,0 +1,23 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { makeLazy } from "./lazy"; + +const NoopComponent = () => null; + +/** + * A lazy component. The factory method is called on first render. + * @param factory Function returning a Component + * @param attempts How many times to try to get the component before giving up + * @returns Result of factory function + */ +export function LazyComponent(factory: () => React.ComponentType, attempts = 5) { + const get = makeLazy(factory, attempts); + return (props: T) => { + const Component = get() ?? NoopComponent; + return ; + }; +} diff --git a/src/utils/react.tsx b/src/utils/react.tsx index 2d2bac39..f31549f1 100644 --- a/src/utils/react.tsx +++ b/src/utils/react.tsx @@ -18,9 +18,10 @@ import { React, useEffect, useMemo, useReducer, useState } from "@webpack/common"; -import { makeLazy } from "./lazy"; import { checkIntersecting } from "./misc"; +export * from "./lazyReact"; + export const NoopComponent = () => null; /** @@ -143,17 +144,3 @@ export function useTimer({ interval = 1000, deps = [] }: TimerOpts) { return time; } - -/** - * A lazy component. The factory method is called on first render. - * @param factory Function returning a Component - * @param attempts How many times to try to get the component before giving up - * @returns Result of factory function - */ -export function LazyComponent(factory: () => React.ComponentType, attempts = 5) { - const get = makeLazy(factory, attempts); - return (props: T) => { - const Component = get() ?? NoopComponent; - return ; - }; -} diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 2c55fd36..b4fdb4e1 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -17,8 +17,8 @@ */ import { proxyLazy } from "@utils/lazy"; +import { LazyComponent } from "@utils/lazyReact"; import { Logger } from "@utils/Logger"; -import { LazyComponent } from "@utils/react"; import type { WebpackInstance } from "discord-types/other"; import { traceFunction } from "../debug/Tracer"; @@ -338,9 +338,6 @@ export function waitFor(filter: string | string[] | FilterFn, callback: Callback else if (typeof filter !== "function") throw new Error("filter must be a string, string[] or function, got " + typeof filter); - const [existing, id] = find(filter!, { isIndirect: true, isWaitFor: true }); - if (existing) return void callback(existing, id); - subscriptions.set(filter, callback); }