diff --git a/app/canvas/[id]/layout.tsx b/app/canvas/[id]/layout.tsx index c7ce48b48..ec2caaff6 100644 --- a/app/canvas/[id]/layout.tsx +++ b/app/canvas/[id]/layout.tsx @@ -2,7 +2,6 @@ import { Metadata } from "next"; import { Suspense } from "react"; export const metadata: Metadata = { - title: "无限画布", description: "AI 驱动的无限画布创作工具", }; diff --git a/app/canvas/[id]/page.tsx b/app/canvas/[id]/page.tsx index 656037de1..8986bddeb 100644 --- a/app/canvas/[id]/page.tsx +++ b/app/canvas/[id]/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useState, useCallback, use } from "react"; +import { useEffect, useState, useCallback, use, useRef } from "react"; import { useRouter, useParams } from "next/navigation"; import useSWR from "swr"; import { @@ -133,6 +133,7 @@ export default function CanvasEditorPage({ params }: PageProps) { const [negativePrompt, setNegativePrompt] = useState(""); const [aspectRatio, setAspectRatio] = useState("1:1"); const [imageCount, setImageCount] = useState(1); + const previousNodeCountRef = useRef(0); // 获取选中的图片节点 const selectedImageNode = selectedNodeIds.length === 1 @@ -191,6 +192,31 @@ export default function CanvasEditorPage({ params }: PageProps) { return () => clearTimeout(saveTimer); }, [nodes, id, isLoading, getCanvasState]); + // 删除节点时立即保存,避免用户立刻刷新后看到被删除节点又出现 + useEffect(() => { + if (isLoading) { + previousNodeCountRef.current = nodes.length; + return; + } + + const previousCount = previousNodeCountRef.current; + const currentCount = nodes.length; + previousNodeCountRef.current = currentCount; + + if (previousCount > currentCount) { + const persistAfterDelete = async () => { + setIsSaving(true); + try { + await canvasService.saveCanvasState(id, getCanvasState()); + } catch (error) { + console.error("Delete immediate save failed:", error); + } + setIsSaving(false); + }; + void persistAfterDelete(); + } + }, [nodes.length, id, isLoading, getCanvasState]); + // 智能命名与缩略图逻辑 useEffect(() => { const autoTitleAndThumbnail = async () => { @@ -558,7 +584,7 @@ export default function CanvasEditorPage({ params }: PageProps) { {/* 4. Floating Sidebar (Right) */}