Guard all commitRename cleanup paths against concurrent renames
All exit paths in commitRename now use a thread-guarded finishRename helper that only clears renamingThreadId when it still matches the original threadId. Prevents a stale onBlur from cancelling a newly started rename on a different thread. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
1 parent
c0ad410467
commit
7edd7e8faf
1 file changed
+13
-9
@@ -514,19 +514,27 @@ export default function Sidebar() {
|
||||
|
||||
const commitRename = useCallback(
|
||||
async (threadId: ThreadId, newTitle: string, originalTitle: string) => {
|
||||
const finishRename = () => {
|
||||
setRenamingThreadId((current) => {
|
||||
if (current !== threadId) return current;
|
||||
renamingInputRef.current = null;
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
const trimmed = newTitle.trim();
|
||||
if (trimmed.length === 0) {
|
||||
toastManager.add({ type: "warning", title: "Thread title cannot be empty" });
|
||||
cancelRename();
|
||||
finishRename();
|
||||
return;
|
||||
}
|
||||
if (trimmed === originalTitle) {
|
||||
cancelRename();
|
||||
finishRename();
|
||||
return;
|
||||
}
|
||||
const api = readNativeApi();
|
||||
if (!api) {
|
||||
cancelRename();
|
||||
finishRename();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -543,13 +551,9 @@ export default function Sidebar() {
|
||||
description: error instanceof Error ? error.message : "An error occurred.",
|
||||
});
|
||||
}
|
||||
setRenamingThreadId((current) => {
|
||||
if (current !== threadId) return current;
|
||||
renamingInputRef.current = null;
|
||||
return null;
|
||||
});
|
||||
finishRename();
|
||||
},
|
||||
[cancelRename],
|
||||
[],
|
||||
);
|
||||
|
||||
const handleThreadContextMenu = useCallback(
|
||||
|
||||
Reference in new issue
Block a user