Skip to content

Commit

Permalink
fix: ReactRouter useMatch & InstrumentedRedirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Delusoire committed Aug 8, 2024
1 parent 66fa7e3 commit 32305b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 14 additions & 5 deletions modules/stdlib/src/webpack/ReactComponents.xpui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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"') &&
Expand Down Expand Up @@ -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<any> = findBy("getInteractionId")(
exportedFunctions,
export const InstrumentedRedirect: React.FC<any> = exportedFunctions.find((f) =>
f.toString().includes("getInteractionId") && /\bto:/.test(f)
);

export const SnackbarProvider: SnackbarProviderT = findBy(
Expand Down Expand Up @@ -161,7 +169,8 @@ export const PanelHeader: React.FC<any> = exportedFunctions.find((m) =>
export const PanelContent: React.FC<any> = exportedForwardRefs.find((f) =>
f.render.toString().includes("fixedHeader")
);
export const PanelSkeleton: React.FC<any> = findBy("label", "aside")(exportedFunctions) ||
export const PanelSkeleton: React.FC<any> =
findBy("label", "aside")(exportedFunctions) ||
findBy((m) => m.render.toString().includes("section"))(exportedForwardRefs);

export const Snackbar = {
Expand Down
12 changes: 8 additions & 4 deletions modules/stdlib/src/webpack/ReactRouter.xpui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(")
);

0 comments on commit 32305b2

Please sign in to comment.