From b08b98102af1ab93f174d0efb5e72e552f4b9648 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 25 Mar 2026 15:24:52 +0800 Subject: [PATCH] fix: reduce canvas request bursts --- app/layout.tsx | 2 +- components/canvas/CanvasChatPanel.tsx | 25 ++++++++++++++++++++++--- components/favicon-updater.tsx | 7 +++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index 4f512b6a5..207d5184c 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -14,7 +14,7 @@ export async function generateMetadata(): Promise { "updatedAt" in settings && settings.updatedAt ? new Date(settings.updatedAt).getTime() : Date.now(); - const faviconUrl = `/api/favicon?v=${updatedAt}-${Date.now()}`; + const faviconUrl = `/api/favicon?v=${updatedAt}`; const metadataBase = process.env.AUTH_URL ? new URL(process.env.AUTH_URL) : undefined; diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index a7a36e271..39640fb9c 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -2244,10 +2244,19 @@ export function CanvasChatPanel({ // 从 API 加载历史消息 const { data: historyData } = useSWR<{ messages: ChatMessage[]; - }>(rawChatId ? `/api/messages?chatId=${rawChatId}` : null, fetcher); + }>(rawChatId ? `/api/messages?chatId=${rawChatId}` : null, fetcher, { + revalidateOnFocus: false, + revalidateOnReconnect: false, + dedupingInterval: 10000, + }); const { data: messageVotes } = useSWR( voteSWRKey, - fetcher + fetcher, + { + revalidateOnFocus: false, + revalidateOnReconnect: false, + dedupingInterval: 60000, + } ); // 获取选中的图片节点 @@ -2745,7 +2754,12 @@ export function CanvasChatPanel({ tags?: CanvasSkillTag[]; }>( "/api/canvas-skill-tags", - fetcher + fetcher, + { + revalidateOnFocus: false, + revalidateOnReconnect: false, + dedupingInterval: 60000, + } ); const { data: membershipSummary } = useSWR<{ isHighVip?: boolean; @@ -2767,6 +2781,11 @@ export function CanvasChatPanel({ const response = await fetch(url, { cache: "no-store" }); if (!response.ok) return null; return response.json(); + }, + { + revalidateOnFocus: false, + revalidateOnReconnect: false, + dedupingInterval: 60000, } ); const { data: agentPresetResponse } = useSWR<{ success?: boolean; data?: AgentPreset }>( diff --git a/components/favicon-updater.tsx b/components/favicon-updater.tsx index e51ab2dbf..047657792 100644 --- a/components/favicon-updater.tsx +++ b/components/favicon-updater.tsx @@ -6,8 +6,11 @@ export function FaviconUpdater() { useEffect(() => { let isDisposed = false; - const timestamp = Date.now(); - const urlWithCache = `/api/favicon?v=${timestamp}`; + const existingIcon = + document.querySelector('link[rel="icon"]')?.href || + document.querySelector('link[rel="shortcut icon"]')?.href || + document.querySelector('link[rel="apple-touch-icon"]')?.href; + const urlWithCache = existingIcon || "/api/favicon"; Promise.resolve().then(() => { if (isDisposed) {