From cba611c1cc46099a191cad64995dc8af8dce7d1a Mon Sep 17 00:00:00 2001 From: Eric <45801973+waresnew@users.noreply.github.com> Date: Mon, 8 Apr 2024 00:33:35 -0400 Subject: [PATCH] Better error for primitives on proxyLazy + fix StartupTimings (#2339) --- src/plugins/startupTimings/index.tsx | 5 +++-- src/utils/lazy.ts | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/startupTimings/index.tsx b/src/plugins/startupTimings/index.tsx index c7417f0f..742d822a 100644 --- a/src/plugins/startupTimings/index.tsx +++ b/src/plugins/startupTimings/index.tsx @@ -17,9 +17,10 @@ */ import { Devs } from "@utils/constants"; -import { LazyComponent } from "@utils/react"; import definePlugin from "@utils/types"; +import StartupTimingPage from "./StartupTimingPage"; + export default definePlugin({ name: "StartupTimings", description: "Adds Startup Timings to the Settings menu", @@ -31,5 +32,5 @@ export default definePlugin({ replace: '{section:"StartupTimings",label:"Startup Timings",element:$self.StartupTimingPage},$&' } }], - StartupTimingPage: LazyComponent(() => require("./StartupTimingPage").default) + StartupTimingPage }); diff --git a/src/utils/lazy.ts b/src/utils/lazy.ts index 32336fb4..a61785df 100644 --- a/src/utils/lazy.ts +++ b/src/utils/lazy.ts @@ -116,8 +116,11 @@ export function proxyLazy(factory: () => T, attempts = 5, isChild = false): T attempts, true ); - - return Reflect.get(target[kGET](), p, receiver); + const lazyTarget = target[kGET](); + if (typeof lazyTarget === "object" || typeof lazyTarget === "function") { + return Reflect.get(lazyTarget, p, receiver); + } + throw new Error("proxyLazy called on a primitive value"); } }) as any; }