Skip to content

Commit 76750fa

Browse files
xlorneclaude
andcommitted
fix: 修复标题配置弹框预览显示问题
- 使用 useState 替代 useRef 避免 React 警告 - 通过参数传递 onChange 回调而非在渲染时赋值 - 修复预览区显示"(自定义配置)"而非实际内容的问题 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d232c58 commit 76750fa

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

  • frontend/packages/flow-pc/flow-pc-design/src/components/design-editor/node-components/strategy

frontend/packages/flow-pc/flow-pc-design/src/components/design-editor/node-components/strategy/node-title.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo, useRef, useState, useCallback } from 'react';
1+
import React, { useMemo, useState, useCallback } from 'react';
22
import { Form, Button, Space } from 'antd';
33
import { EditOutlined } from '@ant-design/icons';
44
import { Field, FieldRenderProps } from '@flowgram.ai/fixed-layout-editor';
@@ -14,8 +14,7 @@ import { TitleConfigModal } from './TitleConfigModal';
1414
export const NodeTitleStrategy: React.FC = () => {
1515
const [showConfigModal, setShowConfigModal] = useState(false);
1616
const [modalScript, setModalScript] = useState('');
17-
// 使用 ref 保存 onChange 回调
18-
const onChangeRef = useRef<((value: string) => void) | null>(null);
17+
const [currentOnChange, setCurrentOnChange] = useState<((value: string) => void) | null>(null);
1918

2019
// 从 design context 获取表单字段
2120
const { state } = useDesignContext();
@@ -63,18 +62,19 @@ export const NodeTitleStrategy: React.FC = () => {
6362
return '(自定义配置)';
6463
}, [mappings]);
6564

66-
const handleOpenConfig = (currentValue: string) => {
65+
const handleOpenConfig = useCallback((currentValue: string, onChange: (value: string) => void) => {
66+
setCurrentOnChange(() => onChange);
6767
setModalScript(currentValue || '');
6868
setShowConfigModal(true);
69-
};
69+
}, []);
7070

7171
const handleConfirm = useCallback((script: string) => {
7272
// 调用 onChange 回调更新编辑器状态
73-
if (onChangeRef.current) {
74-
onChangeRef.current(script);
73+
if (currentOnChange) {
74+
currentOnChange(script);
7575
}
7676
setShowConfigModal(false);
77-
}, []);
77+
}, [currentOnChange]);
7878

7979
return (
8080
<>
@@ -84,8 +84,6 @@ export const NodeTitleStrategy: React.FC = () => {
8484
name="NodeTitleStrategy.script"
8585
render={(props: FieldRenderProps<any>) => {
8686
const { value, onChange } = props.field;
87-
// 保存 onChange 回调到 ref
88-
onChangeRef.current = onChange;
8987

9088
return (
9189
<Space.Compact style={{ width: '100%' }}>
@@ -106,7 +104,7 @@ export const NodeTitleStrategy: React.FC = () => {
106104
</div>
107105
<Button
108106
icon={<EditOutlined />}
109-
onClick={() => handleOpenConfig(value || '')}
107+
onClick={() => handleOpenConfig(value || '', onChange)}
110108
style={{ borderRadius: '0 6px 6px 0' }}
111109
>
112110
编辑

0 commit comments

Comments
 (0)