Skip to content

Commit e3fe298

Browse files
committed
fix re rendering issue
1 parent a12a9b9 commit e3fe298

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

client/packages/lowcoder/src/comps/comps/chatComp/components/ChatContainer.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// client/packages/lowcoder/src/comps/comps/chatComp/components/ChatContainer.tsx
22

3-
import React, { useState, useEffect } from "react";
3+
import React, { useState, useEffect, useRef } from "react";
44
import {
55
useExternalStoreRuntime,
66
ThreadMessageLike,
@@ -83,7 +83,7 @@ const StyledChatContainer = styled.div<ChatCoreProps>`
8383
}
8484
8585
/* Input Field Styles */
86-
.aui-composer-input {
86+
form.aui-composer-root {
8787
background-color: ${(props) => props.inputStyle?.inputBackground || "#ffffff"};
8888
color: ${(props) => props.inputStyle?.inputText || "inherit"};
8989
border-color: ${(props) => props.inputStyle?.inputBorder || "#d1d5db"};
@@ -131,17 +131,25 @@ function ChatContainerView(props: ChatCoreProps) {
131131
const { state, actions } = useChatContext();
132132
const [isRunning, setIsRunning] = useState(false);
133133

134+
// Store callback props in refs so useEffects don't re-fire
135+
// when Lowcoder's builder creates new function references on each render
136+
const onConversationUpdateRef = useRef(props.onConversationUpdate);
137+
onConversationUpdateRef.current = props.onConversationUpdate;
138+
139+
const onEventRef = useRef(props.onEvent);
140+
onEventRef.current = props.onEvent;
141+
134142
const currentMessages = actions.getCurrentMessages();
135143

136144
useEffect(() => {
137145
if (currentMessages.length > 0 && !isRunning) {
138-
props.onConversationUpdate?.(currentMessages);
146+
onConversationUpdateRef.current?.(currentMessages);
139147
}
140-
}, [currentMessages, isRunning, props.onConversationUpdate]);
148+
}, [currentMessages, isRunning]);
141149

142150
useEffect(() => {
143-
props.onEvent?.("componentLoad");
144-
}, [props.onEvent]);
151+
onEventRef.current?.("componentLoad");
152+
}, []);
145153

146154
const convertMessage = (message: ChatMessage): ThreadMessageLike => {
147155
const content: ThreadUserContentPart[] = [{ type: "text", text: message.text }];

client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ export function ChatProvider({ children, storage }: {
360360

361361
// Auto-initialize on mount
362362
useEffect(() => {
363+
console.log("useEffect Inside ChatProvider", state.isInitialized, state.isLoading);
363364
if (!state.isInitialized && !state.isLoading) {
365+
console.log("Initializing chat data...");
364366
initialize();
365367
}
366368
}, [state.isInitialized, state.isLoading]);

0 commit comments

Comments
 (0)