From ebefbeefc830279bad0aa7985d6bf730062ceeec Mon Sep 17 00:00:00 2001 From: Cats Juice Date: Mon, 14 Jul 2025 11:57:51 +0800 Subject: [PATCH] fix(core): prevent creating session every time in chat page (#13190) ## Summary by CodeRabbit * **Bug Fixes** * Improved session handling in chat to prevent redundant session creation and ensure consistent assignment of session functions. --- .../core/src/desktop/pages/workspace/chat/index.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx b/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx index fe2dd9233..c772775fa 100644 --- a/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx +++ b/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx @@ -106,6 +106,9 @@ export const Component = () => { const createSession = useCallback( async (options: Partial = {}) => { + if (currentSession) { + return currentSession; + } const sessionId = await client.createSession({ workspaceId, promptName: 'Chat With AFFiNE AI' satisfies PromptKey, @@ -117,7 +120,7 @@ export const Component = () => { setCurrentSession(session); return session; }, - [client, workspaceId] + [client, currentSession, workspaceId] ); const togglePin = useCallback(async () => { @@ -204,10 +207,10 @@ export const Component = () => { confirmModal.closeConfirmModal, confirmModal.openConfirmModal ); + content.createSession = createSession; if (!chatContent) { // initial values that won't change - content.createSession = createSession; content.independentMode = true; content.onboardingOffsetY = -100; chatContainerRef.current?.append(content);