summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAAGaming <aa@mail.catvibers.me>2022-08-11 20:34:55 -0400
committerAAGaming <aa@mail.catvibers.me>2022-08-11 20:34:55 -0400
commit114c54c9b05b5a7885c1939fb63aa006f879ba53 (patch)
tree2ff94bafee7f81ef50ef05aa37a88c4cc6ccecf3
parent47e0661773d8609cf231d962eaa9cceaac569899 (diff)
downloaddecky-loader-114c54c9b05b5a7885c1939fb63aa006f879ba53.tar.gz
decky-loader-114c54c9b05b5a7885c1939fb63aa006f879ba53.zip
Fix route unpatching
-rw-r--r--frontend/src/router-hook.tsx18
1 files changed, 13 insertions, 5 deletions
diff --git a/frontend/src/router-hook.tsx b/frontend/src/router-hook.tsx
index ca2a7039..e42307ee 100644
--- a/frontend/src/router-hook.tsx
+++ b/frontend/src/router-hook.tsx
@@ -1,5 +1,5 @@
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 {
@@ -40,7 +40,7 @@ class RouterHook extends Logger {
let Route: new () => Route;
// 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 { routes, routePatches } = useDeckyRouterState();
@@ -60,19 +60,27 @@ class RouterHook extends Logger {
routeList[routerIndex] = newRouterArray;
}
routeList.forEach((route: Route, index: number) => {
+ console.log(route);
const replaced = toReplace.get(route?.props?.path as string);
if (replaced) {
- routeList[index] = replaced;
+ routeList[index].props.children = replaced;
toReplace.delete(route?.props?.path as string);
}
if (route?.props?.path && routePatches.has(route.props.path as string)) {
toReplace.set(
route?.props?.path as string,
// @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) => {
- 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;
});
}
});