From c577833e7caa58300741d5f6685a62ec74c16474 Mon Sep 17 00:00:00 2001 From: xuhd Date: Fri, 5 Jun 2026 13:53:10 +0800 Subject: [PATCH] fix(notebook): default material source to notebook when studioToken or initialNotebookId is set Replace useEffect-based approach with synchronous effectiveMaterialSource derived value to avoid first-render flash and timing issues. Co-Authored-By: Claude Sonnet 4.6 --- .../components/ai-writing/AIWritingForm.tsx | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/frontend-web/src/open-canvas/components/ai-writing/AIWritingForm.tsx b/frontend-web/src/open-canvas/components/ai-writing/AIWritingForm.tsx index 53237d53..91bee967 100644 --- a/frontend-web/src/open-canvas/components/ai-writing/AIWritingForm.tsx +++ b/frontend-web/src/open-canvas/components/ai-writing/AIWritingForm.tsx @@ -97,13 +97,10 @@ export function AIWritingForm({ [models, modelName], ); - // initialNotebookId 存在时自动切换素材来源为「我的笔记」 - useEffect(() => { - if (initialNotebookId != null) { - setMaterialSource('notebook'); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + // studioToken / initialNotebookId 存在时强制使用「我的笔记」 + const effectiveMaterialSource: MaterialSource = studioToken ?? initialNotebookId != null + ? 'notebook' + : materialSource; // 初始化时加载文章类型 useEffect(() => { @@ -172,11 +169,11 @@ export function AIWritingForm({ wordCountTarget: wordCount, keywordCount: DEFAULT_KEYWORD_COUNT, writingMode: hideAdvancedFields ? 'loose' : strictMode ? 'strict' : 'loose', - materialSource, + materialSource: effectiveMaterialSource, modelName: selectedModel?.name || modelName || undefined, // 只有选了"我的笔记"才传笔记参数 - noteSearchSpaceId: materialSource === 'notebook' ? (selectedNotebookId ?? undefined) : undefined, - noteSourceIds: materialSource === 'notebook' && selectedNotebookId != null ? selectedDocumentIds : undefined, + noteSearchSpaceId: effectiveMaterialSource === 'notebook' ? (selectedNotebookId ?? undefined) : undefined, + noteSourceIds: effectiveMaterialSource === 'notebook' && selectedNotebookId != null ? selectedDocumentIds : undefined, }); } @@ -284,33 +281,26 @@ export function AIWritingForm({
- {/* studioToken 模式:素材来源已锁定为「我的笔记」,不可切换 */} - {studioToken ? ( -
- 我的笔记 -
- ) : ( - - )} + {/* 选了"我的笔记"才展示笔记本 / 文档选择器 */} - {materialSource === 'notebook' && ( + {effectiveMaterialSource === 'notebook' && (
{/* studioToken 模式:笔记本已锁定,不展示选择器 */} {!studioToken && (