fix: redirect to /chat/id after image generation to ensure messages load correctly
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2fdf27e611
commit
cd5669a8bf
@ -301,10 +301,13 @@ export function Chat({
|
|||||||
// 🆕 收到消息,清除持久化状态
|
// 🆕 收到消息,清除持久化状态
|
||||||
completeGeneration();
|
completeGeneration();
|
||||||
|
|
||||||
// 🆕 如果当前在首页,更新 URL 为 /chat/${id},确保刷新后不会丢失消息
|
// 🆕 如果当前在首页,直接跳转到 /chat/${id},从数据库重新加载消息
|
||||||
|
// 这样可以确保用户消息和生成的图片都正确显示
|
||||||
if (window.location.pathname === "/" || window.location.pathname === "") {
|
if (window.location.pathname === "/" || window.location.pathname === "") {
|
||||||
console.log("[Chat] 更新 URL 到 /chat/" + id);
|
console.log("[Chat] 图片生成完成,跳转到 /chat/" + id);
|
||||||
window.history.replaceState({}, "", `/chat/${id}`);
|
// 使用 location.href 进行完整页面跳转,确保从数据库加载消息
|
||||||
|
window.location.href = `/chat/${id}`;
|
||||||
|
return; // 跳转后不需要更新本地状态
|
||||||
}
|
}
|
||||||
|
|
||||||
setMessages((prevMessages) => {
|
setMessages((prevMessages) => {
|
||||||
@ -350,10 +353,11 @@ export function Chat({
|
|||||||
// 🆕 生成完成,清除持久化状态
|
// 🆕 生成完成,清除持久化状态
|
||||||
completeGeneration();
|
completeGeneration();
|
||||||
|
|
||||||
// 🆕 如果当前在首页,更新 URL 为 /chat/${id},确保刷新后不会丢失消息
|
// 🆕 如果当前在首页,跳转到 /chat/${id},确保消息正确加载
|
||||||
|
// 注意:对于图片生成,data-appendMessage 会先触发跳转,这里是备用逻辑
|
||||||
if (window.location.pathname === "/" || window.location.pathname === "") {
|
if (window.location.pathname === "/" || window.location.pathname === "") {
|
||||||
console.log("[Chat] onFinish: 更新 URL 到 /chat/" + id);
|
console.log("[Chat] onFinish: 跳转到 /chat/" + id);
|
||||||
window.history.replaceState({}, "", `/chat/${id}`);
|
window.location.href = `/chat/${id}`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user