fixed injection watcher
This commit is contained in:
@@ -42,6 +42,7 @@ export default function Chat() {
|
||||
"thinking",
|
||||
);
|
||||
const [liveNotices, setLiveNotices] = useState<string[]>([]);
|
||||
const [chatError, setChatError] = useState<string | null>(null);
|
||||
const messagesRef = useRef<HTMLDivElement>(null);
|
||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||
const scrollRafRef = useRef<number | null>(null);
|
||||
@@ -93,7 +94,7 @@ export default function Chat() {
|
||||
cancelAnimationFrame(scrollRafRef.current);
|
||||
}
|
||||
};
|
||||
}, [messages, streaming, liveNotices, loading, scrollToBottom]);
|
||||
}, [messages, streaming, liveNotices, loading, chatError, scrollToBottom]);
|
||||
|
||||
const dismissKeyboard = useCallback(() => {
|
||||
inputRef.current?.blur();
|
||||
@@ -151,6 +152,7 @@ export default function Chat() {
|
||||
setStreaming("");
|
||||
setPendingPhase("thinking");
|
||||
setLiveNotices([]);
|
||||
setChatError(null);
|
||||
|
||||
const tempUser: ChatMessage = {
|
||||
id: Date.now(),
|
||||
@@ -187,6 +189,7 @@ export default function Chat() {
|
||||
if (chunk.event === "done") {
|
||||
setStreaming("");
|
||||
setLiveNotices([]);
|
||||
setChatError(null);
|
||||
setLoading(false);
|
||||
if (assistantText.trim()) {
|
||||
setMessages((prev) => [
|
||||
@@ -208,8 +211,9 @@ export default function Chat() {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
const message = err instanceof Error ? err.message : "Ошибка чата";
|
||||
setChatError(message);
|
||||
setStreaming("");
|
||||
setLiveNotices([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -310,6 +314,13 @@ export default function Chat() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{chatError && (
|
||||
<div className="message message-error" role="alert">
|
||||
<div className="message-role">ошибка</div>
|
||||
<div className="message-content">{chatError}</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="messages-bottom-anchor" aria-hidden="true" />
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user