From 32305b242636361a3e3e7a2e44f7f3edf6548d38 Mon Sep 17 00:00:00 2001 From: Delusoire Date: Thu, 8 Aug 2024 09:46:59 +0100 Subject: [PATCH] fix: ReactRouter useMatch & InstrumentedRedirect --- .../src/webpack/ReactComponents.xpui.ts | 19 ++++++++++++++----- .../stdlib/src/webpack/ReactRouter.xpui.ts | 12 ++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/modules/stdlib/src/webpack/ReactComponents.xpui.ts b/modules/stdlib/src/webpack/ReactComponents.xpui.ts index c852c64..ee5ccd4 100644 --- a/modules/stdlib/src/webpack/ReactComponents.xpui.ts +++ b/modules/stdlib/src/webpack/ReactComponents.xpui.ts @@ -5,7 +5,13 @@ import { capitalize } from "../../deps.ts"; import { Platform } from "../expose/Platform.ts"; -import { chunks, exportedForwardRefs, exportedFunctions, exportedMemos, require } from "./index.ts"; +import { + chunks, + exportedForwardRefs, + exportedFunctions, + exportedMemos, + require, +} from "./index.ts"; import { findBy } from "/hooks/util.ts"; import { React } from "../expose/React.ts"; @@ -28,7 +34,9 @@ export const Menus: any = Object.fromEntries( }), ); -const [ContextMenuModuleID] = chunks.find(([_, v]) => v.toString().includes("toggleContextMenu"))!; +const [ContextMenuModuleID] = chunks.find(([_, v]) => + v.toString().includes("toggleContextMenu") +)!; const [playlistMenuChunkID] = chunks.find( ([, v]) => v.toString().includes('value:"playlist"') && @@ -106,8 +114,8 @@ export const NavTo: React.NamedExoticComponent = exportedMemoFRefs.find((m) => (m as any).type.render.toString().includes("pageId") )!; -export const InstrumentedRedirect: React.FC = findBy("getInteractionId")( - exportedFunctions, +export const InstrumentedRedirect: React.FC = exportedFunctions.find((f) => + f.toString().includes("getInteractionId") && /\bto:/.test(f) ); export const SnackbarProvider: SnackbarProviderT = findBy( @@ -161,7 +169,8 @@ export const PanelHeader: React.FC = exportedFunctions.find((m) => export const PanelContent: React.FC = exportedForwardRefs.find((f) => f.render.toString().includes("fixedHeader") ); -export const PanelSkeleton: React.FC = findBy("label", "aside")(exportedFunctions) || +export const PanelSkeleton: React.FC = + findBy("label", "aside")(exportedFunctions) || findBy((m) => m.render.toString().includes("section"))(exportedForwardRefs); export const Snackbar = { diff --git a/modules/stdlib/src/webpack/ReactRouter.xpui.ts b/modules/stdlib/src/webpack/ReactRouter.xpui.ts index 1bc85b2..0910715 100644 --- a/modules/stdlib/src/webpack/ReactRouter.xpui.ts +++ b/modules/stdlib/src/webpack/ReactRouter.xpui.ts @@ -4,14 +4,18 @@ */ import { chunks, require } from "./index.ts"; -import { findBy } from "/hooks/util.ts"; + +import type { useMatch as useMatchT } from "npm:react-router"; await CHUNKS.xpui.promise; -const [ReactRouterModuleID] = chunks.find(([_, v]) => v.toString().includes("React Router"))!; +const [ReactRouterModuleID] = chunks.find(([_, v]) => + v.toString().includes("React Router") +)!; const ReactRouterModule = Object.values(require(ReactRouterModuleID)); // https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/hooks.tsx#L131 -export const useMatch: Function = ReactRouterModule.find((f) => - f.toString().includes("let{pathname:") && !f.toString().includes(".createElement(") +export const useMatch: typeof useMatchT = ReactRouterModule.find((f) => + f.toString().includes("let{pathname:") && + !f.toString().includes(".createElement(") );