From fdbc508fa8cb9ad3629486cacc1c92abb2500794 Mon Sep 17 00:00:00 2001
From: AAGaming <aa@mail.catvibers.me>
Date: Sat, 31 Dec 2022 21:53:39 -0500
Subject: Main menu and overlay patching API

---
 frontend/src/router-hook.tsx | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

(limited to 'frontend/src/router-hook.tsx')

diff --git a/frontend/src/router-hook.tsx b/frontend/src/router-hook.tsx
index bf3ae0cb..c24e2a73 100644
--- a/frontend/src/router-hook.tsx
+++ b/frontend/src/router-hook.tsx
@@ -120,6 +120,8 @@ class RouterHook extends Logger {
       return <>{renderedComponents}</>;
     };
 
+    let globalComponents: any;
+
     this.wrapperPatch = afterPatch(this.gamepadWrapper, 'render', (_: any, ret: any) => {
       if (ret?.props?.children?.props?.children?.length == 5 || ret?.props?.children?.props?.children?.length == 4) {
         const idx = ret?.props?.children?.props?.children?.length == 4 ? 1 : 2;
@@ -143,11 +145,17 @@ class RouterHook extends Logger {
             this.memoizedRouter = memo(this.router.type);
             this.memoizedRouter.isDeckyRouter = true;
           }
-          ret.props.children.props.children.push(
-            <DeckyGlobalComponentsStateContextProvider deckyGlobalComponentsState={this.globalComponentsState}>
-              <DeckyGlobalComponentsWrapper />
-            </DeckyGlobalComponentsStateContextProvider>,
-          );
+
+          if (!globalComponents) {
+            globalComponents = (
+              <DeckyGlobalComponentsStateContextProvider deckyGlobalComponentsState={this.globalComponentsState}>
+                <DeckyGlobalComponentsWrapper />
+              </DeckyGlobalComponentsStateContextProvider>
+            );
+          }
+
+          ret.props.children.props.children.push(globalComponents);
+
           ret.props.children.props.children[idx].props.children[0].type = this.memoizedRouter;
         }
       }
-- 
cgit v1.2.3

