Skip to content

Commit fadfbc0

Browse files
authored
clearing chat input when switching apps (dyad-sh#1791)
This PR adresses issue dyad-sh#1735 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Clear chat input and selected component previews when switching apps to prevent state carryover. Fixes dyad-sh#1735. - **Bug Fixes** - Reset chatInputValueAtom and selectedComponentsPreviewAtom on selectedAppId change in RootLayout. - Ensures each app opens with a clean chat and preview state. <sup>Written for commit df16678. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
1 parent 76875fe commit fadfbc0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/app/layout.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ import { Toaster } from "sonner";
66
import { TitleBar } from "./TitleBar";
77
import { useEffect, type ReactNode } from "react";
88
import { useRunApp } from "@/hooks/useRunApp";
9-
import { useAtomValue } from "jotai";
10-
import { previewModeAtom } from "@/atoms/appAtoms";
9+
import { useAtomValue, useSetAtom } from "jotai";
10+
import { previewModeAtom, selectedAppIdAtom } from "@/atoms/appAtoms";
1111
import { useSettings } from "@/hooks/useSettings";
1212
import type { ZoomLevel } from "@/lib/schemas";
13+
import { selectedComponentsPreviewAtom } from "@/atoms/previewAtoms";
14+
import { chatInputValueAtom } from "@/atoms/chatAtoms";
1315

1416
const DEFAULT_ZOOM_LEVEL: ZoomLevel = "100";
1517

1618
export default function RootLayout({ children }: { children: ReactNode }) {
1719
const { refreshAppIframe } = useRunApp();
1820
const previewMode = useAtomValue(previewModeAtom);
1921
const { settings } = useSettings();
22+
const setSelectedComponentsPreview = useSetAtom(
23+
selectedComponentsPreviewAtom,
24+
);
25+
const setChatInput = useSetAtom(chatInputValueAtom);
26+
const selectedAppId = useAtomValue(selectedAppIdAtom);
2027

2128
useEffect(() => {
2229
const zoomLevel = settings?.zoomLevel ?? DEFAULT_ZOOM_LEVEL;
@@ -63,6 +70,11 @@ export default function RootLayout({ children }: { children: ReactNode }) {
6370
};
6471
}, [refreshAppIframe, previewMode]);
6572

73+
useEffect(() => {
74+
setChatInput("");
75+
setSelectedComponentsPreview([]);
76+
}, [selectedAppId]);
77+
6678
return (
6779
<>
6880
<ThemeProvider>

0 commit comments

Comments
 (0)