Files
deer-flow/frontend/src/app/workspace/chats/[thread_id]/layout.tsx

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-01-17 11:02:33 +08:00
"use client";
import { useParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { PromptInputProvider } from "@/components/ai-elements/prompt-input";
2026-01-17 11:02:33 +08:00
import { ArtifactsProvider } from "@/components/workspace/artifacts";
2026-02-07 16:14:48 +08:00
import { SubtasksProvider } from "@/core/tasks/context";
2026-01-17 11:02:33 +08:00
export default function ChatLayout({
children,
}: {
children: React.ReactNode;
}) {
const { thread_id } = useParams<{ thread_id: string }>();
const prevThreadId = useRef(thread_id);
// Increment only when navigating TO "new" from a non-"new" route.
// This forces a full remount of the subtree for a fresh new-chat state,
// without remounting when the URL transitions from "new" → actual-id
// (which would interrupt streaming).
const [generation, setGeneration] = useState(0);
useEffect(() => {
if (thread_id === "new" && prevThreadId.current !== "new") {
setGeneration((g) => g + 1);
}
prevThreadId.current = thread_id;
}, [thread_id]);
return (
<SubtasksProvider key={generation}>
2026-02-07 16:14:48 +08:00
<ArtifactsProvider>
<PromptInputProvider>{children}</PromptInputProvider>
</ArtifactsProvider>
</SubtasksProvider>
);
2026-01-17 11:02:33 +08:00
}