From fadfbc06be8d08efcd0e12a366c881c4df5c9086 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Mejri Date: Fri, 21 Nov 2025 16:06:59 +0100 Subject: [PATCH] clearing chat input when switching apps (#1791) This PR adresses issue #1735 --- ## Summary by cubic Clear chat input and selected component previews when switching apps to prevent state carryover. Fixes #1735. - **Bug Fixes** - Reset chatInputValueAtom and selectedComponentsPreviewAtom on selectedAppId change in RootLayout. - Ensures each app opens with a clean chat and preview state. Written for commit df166781e48934ca1e2b8b2b202daa014c358922. Summary will update automatically on new commits. --- src/app/layout.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/layout.tsx b/src/app/layout.tsx index e280c9a..a400219 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -6,10 +6,12 @@ import { Toaster } from "sonner"; import { TitleBar } from "./TitleBar"; import { useEffect, type ReactNode } from "react"; import { useRunApp } from "@/hooks/useRunApp"; -import { useAtomValue } from "jotai"; -import { previewModeAtom } from "@/atoms/appAtoms"; +import { useAtomValue, useSetAtom } from "jotai"; +import { previewModeAtom, selectedAppIdAtom } from "@/atoms/appAtoms"; import { useSettings } from "@/hooks/useSettings"; import type { ZoomLevel } from "@/lib/schemas"; +import { selectedComponentsPreviewAtom } from "@/atoms/previewAtoms"; +import { chatInputValueAtom } from "@/atoms/chatAtoms"; const DEFAULT_ZOOM_LEVEL: ZoomLevel = "100"; @@ -17,6 +19,11 @@ export default function RootLayout({ children }: { children: ReactNode }) { const { refreshAppIframe } = useRunApp(); const previewMode = useAtomValue(previewModeAtom); const { settings } = useSettings(); + const setSelectedComponentsPreview = useSetAtom( + selectedComponentsPreviewAtom, + ); + const setChatInput = useSetAtom(chatInputValueAtom); + const selectedAppId = useAtomValue(selectedAppIdAtom); useEffect(() => { const zoomLevel = settings?.zoomLevel ?? DEFAULT_ZOOM_LEVEL; @@ -63,6 +70,11 @@ export default function RootLayout({ children }: { children: ReactNode }) { }; }, [refreshAppIframe, previewMode]); + useEffect(() => { + setChatInput(""); + setSelectedComponentsPreview([]); + }, [selectedAppId]); + return ( <>