Skip to content

Commit 658e78f

Browse files
committed
fix(web): refit the parent breadcrumb after rename
1 parent 660773a commit 658e78f

1 file changed

Lines changed: 36 additions & 34 deletions

File tree

‎apps/web/src/components/chat/ChatHeader.tsx‎

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,41 @@ export const ChatHeader = memo(function ChatHeader({
9191
const interfaceFont = useClientSettings((settings) => settings.fontFamilySans);
9292
const breadcrumbContainerRef = useRef<HTMLDivElement>(null);
9393
const [collapseParentTitle, setCollapseParentTitle] = useState(false);
94+
const activeThreadRef = useMemo(
95+
() => scopeThreadRef(activeThreadEnvironmentId, activeThreadId),
96+
[activeThreadEnvironmentId, activeThreadId],
97+
);
98+
const canOperateThread = useEnvironmentScope(
99+
activeThreadEnvironmentId,
100+
AuthOrchestrationOperateScope,
101+
);
102+
const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {
103+
reportFailure: false,
104+
});
105+
// Inline rename, keyed by thread: navigating away drops an in-progress
106+
// rename instead of committing stale text. Cleared on thread change (not
107+
// just hidden) so returning to the thread doesn't revive the old draft.
108+
const [renaming, setRenaming] = useState<{
109+
threadId: ThreadId;
110+
environmentId: EnvironmentId;
111+
title: string;
112+
} | null>(null);
113+
if (
114+
renaming !== null &&
115+
(renaming.threadId !== activeThreadId ||
116+
renaming.environmentId !== activeThreadEnvironmentId ||
117+
!canOperateThread)
118+
) {
119+
setRenaming(null);
120+
}
121+
const renamingTitle =
122+
canOperateThread &&
123+
renaming?.threadId === activeThreadId &&
124+
renaming.environmentId === activeThreadEnvironmentId
125+
? renaming.title
126+
: null;
127+
// Leaving rename swaps the input back for the title, which needs a fresh fit.
128+
const isRenamingTitle = renamingTitle !== null;
94129
useEffect(() => {
95130
const list = breadcrumbContainerRef.current?.querySelector("ol");
96131
if (!list || !parentThreadLink) return;
@@ -126,40 +161,7 @@ export const ChatHeader = memo(function ChatHeader({
126161
document.fonts.removeEventListener("loadingdone", measure);
127162
observer.disconnect();
128163
};
129-
}, [activeProjectName, activeThreadTitle, parentThreadLink, interfaceFont]);
130-
const activeThreadRef = useMemo(
131-
() => scopeThreadRef(activeThreadEnvironmentId, activeThreadId),
132-
[activeThreadEnvironmentId, activeThreadId],
133-
);
134-
const canOperateThread = useEnvironmentScope(
135-
activeThreadEnvironmentId,
136-
AuthOrchestrationOperateScope,
137-
);
138-
const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {
139-
reportFailure: false,
140-
});
141-
// Inline rename, keyed by thread: navigating away drops an in-progress
142-
// rename instead of committing stale text. Cleared on thread change (not
143-
// just hidden) so returning to the thread doesn't revive the old draft.
144-
const [renaming, setRenaming] = useState<{
145-
threadId: ThreadId;
146-
environmentId: EnvironmentId;
147-
title: string;
148-
} | null>(null);
149-
if (
150-
renaming !== null &&
151-
(renaming.threadId !== activeThreadId ||
152-
renaming.environmentId !== activeThreadEnvironmentId ||
153-
!canOperateThread)
154-
) {
155-
setRenaming(null);
156-
}
157-
const renamingTitle =
158-
canOperateThread &&
159-
renaming?.threadId === activeThreadId &&
160-
renaming.environmentId === activeThreadEnvironmentId
161-
? renaming.title
162-
: null;
164+
}, [activeProjectName, activeThreadTitle, parentThreadLink, interfaceFont, isRenamingTitle]);
163165
const renameCommittedRef = useRef(false);
164166
const startRename = useCallback(() => {
165167
if (

0 commit comments

Comments
 (0)