From f5717842312afe57fa204b1dc4258d22cd6ce7cd Mon Sep 17 00:00:00 2001 From: sadan4 <117494111+sadan4@users.noreply.github.com> Date: Fri, 24 Apr 2026 13:52:53 -0400 Subject: [PATCH] fix plugins with lazy loaded finds (#4146) Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> --- src/debug/loadLazyChunks.ts | 7 ----- .../reviewDB/components/ReviewModal.tsx | 30 ++++++++++++------- .../components/Code.tsx | 3 +- .../components/Highlighter.tsx | 4 +-- src/plugins/shikiCodeblocks.desktop/index.ts | 2 ++ .../shikiCodeblocks.desktop/utils/misc.ts | 5 +++- src/webpack/common/components.ts | 6 ++-- src/webpack/common/utils.ts | 2 -- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts index 920ce3067..72ded48bb 100644 --- a/src/debug/loadLazyChunks.ts +++ b/src/debug/loadLazyChunks.ts @@ -204,13 +204,6 @@ export async function loadLazyChunks() { } }))); - // Manually require all modules to make sure all lazily required modules are patched - for (const moduleId of Object.keys(wreq.m)) { - try { - wreq(moduleId); - } catch { } - } - LazyChunkLoaderLogger.log("Finished loading all chunks!"); } catch (e) { LazyChunkLoaderLogger.log("A fatal error occurred:", e); diff --git a/src/plugins/reviewDB/components/ReviewModal.tsx b/src/plugins/reviewDB/components/ReviewModal.tsx index c4da56642..8563aa294 100644 --- a/src/plugins/reviewDB/components/ReviewModal.tsx +++ b/src/plugins/reviewDB/components/ReviewModal.tsx @@ -21,13 +21,19 @@ import { Auth } from "@plugins/reviewDB/auth"; import { ReviewType } from "@plugins/reviewDB/entities"; import { REVIEWS_PER_PAGE, UserReviewsData } from "@plugins/reviewDB/reviewDbApi"; import { cl } from "@plugins/reviewDB/utils"; -import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal"; +import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModalLazy } from "@utils/modal"; import { useForceUpdater } from "@utils/react"; -import { Paginator, Text, useRef, useState } from "@webpack/common"; +import * as t from "@vencord/discord-types"; +import { DefaultExtractAndLoadChunksRegex, extractAndLoadChunksLazy, findComponentByCodeLazy } from "@webpack"; +import { Text, useRef, useState } from "@webpack/common"; +import { ComponentProps } from "react"; import ReviewComponent from "./ReviewComponent"; import ReviewsView, { ReviewsInputComponent } from "./ReviewsView"; +const Paginator = findComponentByCodeLazy>('rel:"prev",children:'); +const requirePaginator = extractAndLoadChunksLazy(['name:"SearchResults"'], new RegExp(`${DefaultExtractAndLoadChunksRegex.source}.{0,30}?name:"SearchResults"`)); + function Modal({ modalProps, modalKey, discordId, name, type }: { modalProps: any; modalKey: string, discordId: string; name: string; type: ReviewType; }) { const [data, setData] = useState(); const [signal, refetch] = useForceUpdater(true); @@ -100,13 +106,15 @@ function Modal({ modalProps, modalKey, discordId, name, type }: { modalProps: an export function openReviewsModal(discordId: string, name: string, type: ReviewType) { const modalKey = "vc-rdb-modal-" + Date.now(); - openModal(props => ( - - ), { modalKey }); + openModalLazy(async () => { + await requirePaginator(); + return props => ( + + ); + }, { modalKey }); } diff --git a/src/plugins/shikiCodeblocks.desktop/components/Code.tsx b/src/plugins/shikiCodeblocks.desktop/components/Code.tsx index 5c924f8e9..a4667d490 100644 --- a/src/plugins/shikiCodeblocks.desktop/components/Code.tsx +++ b/src/plugins/shikiCodeblocks.desktop/components/Code.tsx @@ -16,9 +16,8 @@ * along with this program. If not, see . */ -import { cl } from "@plugins/shikiCodeblocks.desktop/utils/misc"; +import { cl, hljs } from "@plugins/shikiCodeblocks.desktop/utils/misc"; import type { IThemedToken } from "@vap/shiki"; -import { hljs } from "@webpack/common"; import { JSX } from "react"; import { ThemeBase } from "./Highlighter"; diff --git a/src/plugins/shikiCodeblocks.desktop/components/Highlighter.tsx b/src/plugins/shikiCodeblocks.desktop/components/Highlighter.tsx index 8bacf0cb8..8da163cec 100644 --- a/src/plugins/shikiCodeblocks.desktop/components/Highlighter.tsx +++ b/src/plugins/shikiCodeblocks.desktop/components/Highlighter.tsx @@ -22,9 +22,9 @@ import { shiki } from "@plugins/shikiCodeblocks.desktop/api/shiki"; import { useShikiSettings } from "@plugins/shikiCodeblocks.desktop/hooks/useShikiSettings"; import { useTheme } from "@plugins/shikiCodeblocks.desktop/hooks/useTheme"; import { hex2Rgb } from "@plugins/shikiCodeblocks.desktop/utils/color"; -import { cl, shouldUseHljs } from "@plugins/shikiCodeblocks.desktop/utils/misc"; +import { cl, hljs, shouldUseHljs } from "@plugins/shikiCodeblocks.desktop/utils/misc"; import { useAwaiter, useIntersection } from "@utils/react"; -import { hljs, React } from "@webpack/common"; +import { React } from "@webpack/common"; import { ButtonRow } from "./ButtonRow"; import { Code } from "./Code"; diff --git a/src/plugins/shikiCodeblocks.desktop/index.ts b/src/plugins/shikiCodeblocks.desktop/index.ts index fbc03854a..975670877 100644 --- a/src/plugins/shikiCodeblocks.desktop/index.ts +++ b/src/plugins/shikiCodeblocks.desktop/index.ts @@ -29,6 +29,7 @@ import deviconStyle from "./devicon.css?managed"; import { settings } from "./settings"; import { DeviconSetting } from "./types"; import { clearStyles } from "./utils/createStyle"; +import { requireHljs } from "./utils/misc"; export default definePlugin({ name: "ShikiCodeblocks", @@ -74,6 +75,7 @@ export default definePlugin({ shiki, createHighlighter, renderHighlighter: ({ lang, content }: { lang: string; content: string; }) => { + requireHljs(); return createHighlighter({ lang: lang?.toLowerCase(), content, diff --git a/src/plugins/shikiCodeblocks.desktop/utils/misc.ts b/src/plugins/shikiCodeblocks.desktop/utils/misc.ts index 1b2fd27c5..70920fda1 100644 --- a/src/plugins/shikiCodeblocks.desktop/utils/misc.ts +++ b/src/plugins/shikiCodeblocks.desktop/utils/misc.ts @@ -20,10 +20,13 @@ import { resolveLang } from "@plugins/shikiCodeblocks.desktop/api/languages"; import { HighlighterProps } from "@plugins/shikiCodeblocks.desktop/components/Highlighter"; import { HljsSetting } from "@plugins/shikiCodeblocks.desktop/types"; import { classNameFactory } from "@utils/css"; -import { hljs } from "@webpack/common"; +import { DefaultExtractAndLoadChunksRegex, extractAndLoadChunksLazy, findByPropsLazy } from "@webpack"; export const cl = classNameFactory("vc-shiki-"); +export const hljs: typeof import("highlight.js").default = findByPropsLazy("highlight", "registerLanguage"); +export const requireHljs = extractAndLoadChunksLazy(["codeBlock:{react("], new RegExp(`"hljs".+?${DefaultExtractAndLoadChunksRegex.source}`)); + export const shouldUseHljs = ({ lang, tryHljs, diff --git a/src/webpack/common/components.ts b/src/webpack/common/components.ts index 9024f8705..cf11deeae 100644 --- a/src/webpack/common/components.ts +++ b/src/webpack/common/components.ts @@ -56,15 +56,15 @@ export const Tooltip = waitForComponent("Tooltip", m => m.prototype?. /** @deprecated import from @vencord/components */ export const TooltipContainer = TooltipContainerComponent as never; -export const TextInput = waitForComponent("TextInput", filters.componentByCode("#{intl::MAXIMUM_LENGTH_ERROR}", '"input"')); -export const TextArea = waitForComponent("TextArea", filters.componentByCode('"data-mana-component":"text-area"')); +// FIXME: t.TextInput was for the old void components, and is not 100% correct for the mana component +export const TextInput = waitForComponent("TextInput", filters.componentByCode('setHasValue?.(""!==', '="text",')); +export const TextArea = waitForComponent("TextArea", filters.componentByCode("!0,rows:", "showRemainingCharacterCount:")); export const Select = waitForComponent("Select", filters.componentByCode('selectionMode:"single",onSelectionChange:', "isSelected:")); export const SearchableSelect = waitForComponent("SearchableSelect", filters.componentByCode('?"multiple":"single",required:')); export const Slider = waitForComponent("Slider", filters.componentByCode("markDash", "this.renderMark(")); export const Popout = waitForComponent("Popout", filters.componentByCode("ref:this.ref,", "renderPopout:this.renderPopout,")); export const Dialog = waitForComponent("Dialog", filters.componentByCode('role:"dialog",tabIndex:-1')); export const TabBar = waitForComponent("TabBar", filters.componentByCode("ref:this.tabBarRef,className:")); -export const Paginator = waitForComponent("Paginator", filters.componentByCode('rel:"prev",children:')); // TODO: remake this component export const Clickable = waitForComponent("Clickable", filters.componentByCode("this.context?this.renderNonInteractive():")); export const Avatar = waitForComponent("Avatar", filters.componentByCode(".size-1.375*")); diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index ee39dcb69..49c764346 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -46,8 +46,6 @@ export const Constants: t.Constants = mapMangledModuleLazy('ME:"/users/@me"', { export const RestAPI: t.RestAPI = findLazy(m => typeof m === "object" && m.del && m.put); export const moment: typeof import("moment") = findByPropsLazy("parseTwoDigitYear"); -export const hljs: typeof import("highlight.js").default = findByPropsLazy("highlight", "registerLanguage"); - export const { match, P }: { match: typeof TSPattern["match"], P: typeof TSPattern["P"]; } = mapMangledModuleLazy("@ts-pattern/matcher", { match: filters.byCode("return new"), P: filters.byProps("when")