|
1 | 1 | // client/packages/lowcoder/src/comps/comps/chatComp/components/ChatContainer.tsx |
2 | 2 |
|
3 | | -import React, { useState, useEffect } from "react"; |
| 3 | +import React, { useState, useEffect, useRef } from "react"; |
4 | 4 | import { |
5 | 5 | useExternalStoreRuntime, |
6 | 6 | ThreadMessageLike, |
@@ -83,7 +83,7 @@ const StyledChatContainer = styled.div<ChatCoreProps>` |
83 | 83 | } |
84 | 84 |
|
85 | 85 | /* Input Field Styles */ |
86 | | - .aui-composer-input { |
| 86 | + form.aui-composer-root { |
87 | 87 | background-color: ${(props) => props.inputStyle?.inputBackground || "#ffffff"}; |
88 | 88 | color: ${(props) => props.inputStyle?.inputText || "inherit"}; |
89 | 89 | border-color: ${(props) => props.inputStyle?.inputBorder || "#d1d5db"}; |
@@ -131,17 +131,25 @@ function ChatContainerView(props: ChatCoreProps) { |
131 | 131 | const { state, actions } = useChatContext(); |
132 | 132 | const [isRunning, setIsRunning] = useState(false); |
133 | 133 |
|
| 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 | + |
134 | 142 | const currentMessages = actions.getCurrentMessages(); |
135 | 143 |
|
136 | 144 | useEffect(() => { |
137 | 145 | if (currentMessages.length > 0 && !isRunning) { |
138 | | - props.onConversationUpdate?.(currentMessages); |
| 146 | + onConversationUpdateRef.current?.(currentMessages); |
139 | 147 | } |
140 | | - }, [currentMessages, isRunning, props.onConversationUpdate]); |
| 148 | + }, [currentMessages, isRunning]); |
141 | 149 |
|
142 | 150 | useEffect(() => { |
143 | | - props.onEvent?.("componentLoad"); |
144 | | - }, [props.onEvent]); |
| 151 | + onEventRef.current?.("componentLoad"); |
| 152 | + }, []); |
145 | 153 |
|
146 | 154 | const convertMessage = (message: ChatMessage): ThreadMessageLike => { |
147 | 155 | const content: ThreadUserContentPart[] = [{ type: "text", text: message.text }]; |
|
0 commit comments