Skip to content

Commit df4866c

Browse files
committed
fix(session): 行内改名同步防连点(ref 拦截同 tick 双击)
1 parent 3dfc12d commit df4866c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎app/src/components/SessionListRow.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ export default function SessionListRow({
8787
// 重命名期间输入框内容(随请求启动重置为服务端标题)
8888
const [value, setValue] = useState("");
8989
const [echo, setEcho] = useState<string | null>(null);
90-
// busy=提交中(响应式——输入框禁用防连点);editingRef=编辑态镜像
91-
// (Esc/提交后 blur 不再触发重复提交——移除节点时 focusout 竞态)
90+
// busy=提交中:state 供输入框禁用视觉;busyRef 供同步判定(state 更新
91+
// 异步——同 tick 双击 Enter 需 ref 立即拦截防连点);editingRef=编辑态
92+
// 镜像(Esc/提交后 blur 不再触发重复提交——移除节点时 focusout 竞态)
9293
const [busy, setBusy] = useState(false);
94+
const busyRef = useRef(false);
9395
const editingRef = useRef(false);
9496
const inputRef = useRef<HTMLInputElement>(null);
9597

@@ -114,12 +116,13 @@ export default function SessionListRow({
114116

115117
/** Enter/失焦提交:空标题或未变化=放弃退出(与详情页 ✎ 同口径) */
116118
const commitRename = async () => {
117-
if (!editingRef.current || busy) return;
119+
if (!editingRef.current || busyRef.current) return;
118120
const t = value.trim();
119121
if (!t || t === s.title) {
120122
endRename();
121123
return;
122124
}
125+
busyRef.current = true;
123126
setBusy(true);
124127
try {
125128
await invoke("update_session_title", { id: s.id, title: t });
@@ -131,6 +134,7 @@ export default function SessionListRow({
131134
} catch (e) {
132135
showToast(`改名失败: ${e}`, "err");
133136
} finally {
137+
busyRef.current = false;
134138
setBusy(false);
135139
}
136140
};

0 commit comments

Comments
 (0)