Skip to content

Commit 655fe42

Browse files
committed
Preview not working
1 parent b497c51 commit 655fe42

File tree

11 files changed

+507
-166
lines changed

11 files changed

+507
-166
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ChatPanel.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { chatMessagesAtom, chatStreamCountAtom } from "../atoms/chatAtoms";
44
import { isTodoPanelOpenAtom } from "../atoms/todoAtoms";
55
import { IpcClient } from "@/ipc/ipc_client";
66
import { useSettings } from "@/hooks/useSettings";
7+
import { AppOutput } from "@/ipc/ipc_types";
78

89
import { ChatHeader } from "./chat/ChatHeader";
910
import { MessagesList } from "./chat/MessagesList";
@@ -37,6 +38,9 @@ export function ChatPanel({
3738
const [error, setError] = useState<string | null>(null);
3839
const streamCount = useAtomValue(chatStreamCountAtom);
3940

41+
// State to track system messages for auto-scrolling
42+
const [systemMessageCount, setSystemMessageCount] = useState(0);
43+
4044
// Debug logging
4145
console.log("ChatPanel render:", { isBackendMode, isFullstackMode, isFrontendMode, isTodoPanelOpen, showTodoToggle: isFullstackMode || isFrontendMode });
4246
// Reference to store the processed prompt so we don't submit it twice
@@ -79,6 +83,43 @@ export function ChatPanel({
7983
scrollToBottom();
8084
}, [streamCount]);
8185

86+
// Set up system message handler for auto-scrolling
87+
useEffect(() => {
88+
const handleAppOutput = (output: AppOutput) => {
89+
// Increment counter to trigger auto-scroll for system messages
90+
setSystemMessageCount(prev => prev + 1);
91+
};
92+
93+
// Register the callback with IpcClient
94+
if (chatId) {
95+
IpcClient.getInstance().runApp(chatId, handleAppOutput);
96+
}
97+
98+
// Cleanup function
99+
return () => {
100+
if (chatId) {
101+
IpcClient.getInstance().stopApp(chatId);
102+
}
103+
};
104+
}, [chatId]);
105+
106+
// Auto-scroll when system messages arrive
107+
useEffect(() => {
108+
if (!isUserScrolling && systemMessageCount > 0) {
109+
const { scrollTop, clientHeight, scrollHeight } =
110+
messagesContainerRef.current || { scrollTop: 0, clientHeight: 0, scrollHeight: 0 };
111+
const threshold = 280;
112+
const isNearBottom =
113+
scrollHeight - (scrollTop + clientHeight) <= threshold;
114+
115+
if (isNearBottom) {
116+
requestAnimationFrame(() => {
117+
scrollToBottom("instant");
118+
});
119+
}
120+
}
121+
}, [systemMessageCount, isUserScrolling]);
122+
82123
useEffect(() => {
83124
const container = messagesContainerRef.current;
84125
if (container) {

src/components/preview_panel/PreviewIframe.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -557,19 +557,27 @@ export const PreviewIframe = ({ loading }: { loading: boolean }) => {
557557
</p>
558558
</div>
559559
) : (
560-
<iframe
561-
sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-orientation-lock allow-pointer-lock allow-presentation allow-downloads"
562-
data-testid="preview-iframe-element"
563-
onLoad={() => {
564-
setErrorMessage(undefined);
565-
}}
566-
ref={iframeRef}
567-
key={reloadKey}
568-
title={`Preview for App ${selectedAppId}`}
569-
className="w-full h-full border-none bg-white dark:bg-gray-950"
570-
src={appUrl}
571-
allow="clipboard-read; clipboard-write; fullscreen; microphone; camera; display-capture; geolocation; autoplay; picture-in-picture"
572-
/>
560+
<>
561+
{console.log(`[IFRAME] Rendering with URL: ${appUrl}`)}
562+
<iframe
563+
sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-orientation-lock allow-pointer-lock allow-presentation allow-downloads"
564+
data-testid="preview-iframe-element"
565+
onLoad={() => {
566+
console.log(`[IFRAME] Successfully loaded URL: ${appUrl}`);
567+
setErrorMessage(undefined);
568+
}}
569+
onError={(e) => {
570+
console.error(`[IFRAME] Error loading: ${appUrl}`, e);
571+
setErrorMessage(`Failed to load app preview: ${e}`);
572+
}}
573+
ref={iframeRef}
574+
key={reloadKey}
575+
title={`Preview for App ${selectedAppId}`}
576+
className="w-full h-full border-none bg-white dark:bg-gray-950"
577+
src={appUrl}
578+
allow="clipboard-read; clipboard-write; fullscreen; microphone; camera; display-capture; geolocation; autoplay; picture-in-picture"
579+
/>
580+
</>
573581
)}
574582
</div>
575583
</div>

src/components/preview_panel/PreviewPanel.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,14 @@ export function PreviewPanel() {
7373
useEffect(() => {
7474
if (
7575
settings?.selectedChatMode === "backend" &&
76-
previewMode === "preview" &&
77-
settings?.fullstackDevelopmentMode !== true
76+
previewMode === "preview"
7877
) {
7978
setPreviewMode("code");
8079
}
8180
}, [
8281
settings?.selectedChatMode,
8382
previewMode,
8483
setPreviewMode,
85-
settings?.fullstackDevelopmentMode,
8684
]);
8785

8886

src/hooks/useRunApp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function useRunApp() {
3333
const proxyUrl = newFormatMatch[1];
3434
const localPort = newFormatMatch[2];
3535
const originalUrl = `http://localhost:${localPort}`;
36+
console.log(`[PROXY] Setting app URL to proxy: ${proxyUrl} (original: ${originalUrl})`);
3637
setAppUrlObj({
3738
appUrl: proxyUrl,
3839
appId: output.appId,

0 commit comments

Comments
 (0)