mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-25 07:04:44 +08:00
fix(frontend): fix new-chat navigation stale state issue (#1077)
- Use router.replace() instead of history.replaceState() so Next.js router's internal state is updated on chat start. This ensures subsequent "New Chat" clicks are treated as a real cross-route navigation (actual-id → "new") rather than a no-op same-path navigation, which was causing stale content to persist. - In ChatLayout, increment the SubtasksProvider key only when navigating TO "new" from a non-"new" route. This forces a full remount for a fresh new-chat state without remounting when the URL transitions from "new" → actual-id (which would interrupt streaming). Made-with: Cursor Co-authored-by: DanielWalnut <45447813+hetaoBackend@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useCallback } from "react";
|
||||
|
||||
import { type PromptInputMessage } from "@/components/ai-elements/prompt-input";
|
||||
@@ -25,6 +26,7 @@ import { cn } from "@/lib/utils";
|
||||
|
||||
export default function ChatPage() {
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const [settings, setSettings] = useLocalSettings();
|
||||
|
||||
const { threadId, isNewThread, setIsNewThread, isMock } = useThreadChat();
|
||||
@@ -38,7 +40,11 @@ export default function ChatPage() {
|
||||
isMock,
|
||||
onStart: () => {
|
||||
setIsNewThread(false);
|
||||
history.replaceState(null, "", `/workspace/chats/${threadId}`);
|
||||
// Use router.replace so Next.js Router's internal state is updated.
|
||||
// This ensures subsequent "New Chat" clicks are treated as a real
|
||||
// cross-route navigation (actual-id → "new") rather than a no-op
|
||||
// same-path navigation, which was causing stale content to persist.
|
||||
router.replace(`/workspace/chats/${threadId}`);
|
||||
},
|
||||
onFinish: (state) => {
|
||||
if (document.hidden || !document.hasFocus()) {
|
||||
|
||||
Reference in New Issue
Block a user