mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-06-17 08:47:49 +00:00
Fix route unpatching
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { afterPatch, findModuleChild, unpatch } from 'decky-frontend-lib';
|
import { afterPatch, findModuleChild, unpatch } from 'decky-frontend-lib';
|
||||||
import { ReactElement, createElement, memo } from 'react';
|
import React, { ReactElement, cloneElement, createElement, memo } from 'react';
|
||||||
import type { Route, RouteProps } from 'react-router';
|
import type { Route, RouteProps } from 'react-router';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -40,7 +40,7 @@ class RouterHook extends Logger {
|
|||||||
|
|
||||||
let Route: new () => Route;
|
let Route: new () => Route;
|
||||||
// Used to store the new replicated routes we create to allow routes to be unpatched.
|
// Used to store the new replicated routes we create to allow routes to be unpatched.
|
||||||
let toReplace = new Map<string, Route>();
|
let toReplace = new Map<string, ReactNode>();
|
||||||
const DeckyWrapper = ({ children }: { children: ReactElement }) => {
|
const DeckyWrapper = ({ children }: { children: ReactElement }) => {
|
||||||
const { routes, routePatches } = useDeckyRouterState();
|
const { routes, routePatches } = useDeckyRouterState();
|
||||||
|
|
||||||
@@ -60,19 +60,27 @@ class RouterHook extends Logger {
|
|||||||
routeList[routerIndex] = newRouterArray;
|
routeList[routerIndex] = newRouterArray;
|
||||||
}
|
}
|
||||||
routeList.forEach((route: Route, index: number) => {
|
routeList.forEach((route: Route, index: number) => {
|
||||||
|
console.log(route);
|
||||||
const replaced = toReplace.get(route?.props?.path as string);
|
const replaced = toReplace.get(route?.props?.path as string);
|
||||||
if (replaced) {
|
if (replaced) {
|
||||||
routeList[index] = replaced;
|
routeList[index].props.children = replaced;
|
||||||
toReplace.delete(route?.props?.path as string);
|
toReplace.delete(route?.props?.path as string);
|
||||||
}
|
}
|
||||||
if (route?.props?.path && routePatches.has(route.props.path as string)) {
|
if (route?.props?.path && routePatches.has(route.props.path as string)) {
|
||||||
toReplace.set(
|
toReplace.set(
|
||||||
route?.props?.path as string,
|
route?.props?.path as string,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
createElement(routeList[index].type, routeList[index].props, routeList[index].props.children),
|
routeList[index].props.children,
|
||||||
);
|
);
|
||||||
routePatches.get(route.props.path as string)?.forEach((patch) => {
|
routePatches.get(route.props.path as string)?.forEach((patch) => {
|
||||||
routeList[index].props = patch(routeList[index].props);
|
const oType = routeList[index].props.children.type;
|
||||||
|
routeList[index].props.children = patch({
|
||||||
|
...routeList[index].props,
|
||||||
|
children: {
|
||||||
|
...cloneElement(routeList[index].props.children),
|
||||||
|
type: (props) => createElement(oType, props),
|
||||||
|
},
|
||||||
|
}).children;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user