fix(web): 修复 useChat 无限请求问题
- 用 useRef 存储回调函数,避免依赖变化导致无限循环 - 添加 onSessionNotFound 回调,会话不存在时自动创建新会话 - 限制 WebSocket 重连次数为 5 次 - 添加 web:dev 快捷脚本
This commit is contained in:
@@ -10,9 +10,10 @@ import { ChatInput } from '../components/ChatInput';
|
||||
|
||||
interface ChatPageProps {
|
||||
sessionId: string;
|
||||
onSessionNotFound?: () => void;
|
||||
}
|
||||
|
||||
export function ChatPage({ sessionId }: ChatPageProps) {
|
||||
export function ChatPage({ sessionId, onSessionNotFound }: ChatPageProps) {
|
||||
const {
|
||||
messages,
|
||||
isConnected,
|
||||
@@ -25,6 +26,7 @@ export function ChatPage({ sessionId }: ChatPageProps) {
|
||||
onError: (error) => {
|
||||
console.error('Chat error:', error);
|
||||
},
|
||||
onSessionNotFound,
|
||||
});
|
||||
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
Reference in New Issue
Block a user