From 90b4aff846fb4eab62bbf1fa80cd605ca9b62f59 Mon Sep 17 00:00:00 2001 From: Tanish Manku <-h> Date: Fri, 21 Mar 2025 23:56:50 -0700 Subject: [PATCH] Fix: Multiple invokes of a prompt after changing mode --- .../GenerationRootComponent.tsx | 7 +++++-- frontend/realtime/src/app/pages/main/index.tsx | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/realtime/src/GenerationRootComponent/GenerationRootComponent.tsx b/frontend/realtime/src/GenerationRootComponent/GenerationRootComponent.tsx index 7babd10362..325e2f861d 100644 --- a/frontend/realtime/src/GenerationRootComponent/GenerationRootComponent.tsx +++ b/frontend/realtime/src/GenerationRootComponent/GenerationRootComponent.tsx @@ -10,7 +10,11 @@ import { Transition } from "@headlessui/react"; import { GenerationEngine } from "~/KonvaApp/GenerationEngine"; import { ensureBase64Prefix } from "~/KonvaApp/EngineUtitlities/Base64Helpers"; -export const GenerationRootComponent = () => { +export const GenerationRootComponent = ({ + generationEngineRef, +}: { + generationEngineRef: React.MutableRefObject; +}) => { // This is a hook that will log the number of times the component has rerendered // Let's make sure we only log once useRenderCounter("GenerationRootComponent"); @@ -19,7 +23,6 @@ export const GenerationRootComponent = () => { const generationState = generationSignal.value; const inputRef = useRef(null); const [isInputFocused, setIsInputFocused] = useState(false); - const generationEngineRef = useRef(null); if (generationEngineRef.current === null) { generationEngineRef.current = new GenerationEngine(); diff --git a/frontend/realtime/src/app/pages/main/index.tsx b/frontend/realtime/src/app/pages/main/index.tsx index 3f860534cd..bf3d039a28 100644 --- a/frontend/realtime/src/app/pages/main/index.tsx +++ b/frontend/realtime/src/app/pages/main/index.tsx @@ -14,6 +14,9 @@ import { appMode } from "~/signals"; import { useSignals } from "@preact/signals-react/runtime"; import { GenerationRootComponent } from "~/GenerationRootComponent/GenerationRootComponent"; import { EditModeRootComponent } from "~/EditModeRootComponent/EditModeRootComponent"; +import { useRef } from "react"; +import { EngineType } from "~/KonvaApp"; +import { GenerationEngine } from "~/KonvaApp/GenerationEngine"; export const Main = withProtectionRoute(() => { // This is a hook that will log the number of times the component has rerendered @@ -26,6 +29,9 @@ export const Main = withProtectionRoute(() => { useSignals(); + const realtimeEngineRef = useRef(null); + const generationEngineRef = useRef(null); + const appModeValue = appMode.value; let childView; @@ -36,7 +42,9 @@ export const Main = withProtectionRoute(() => { ); break; case "generate": - childView = ; + childView = ( + + ); break; case "realtime": default: