fix(webui): avoid remounting outgoing conversations (#6540)
* fix(webui): avoid remounting outgoing conversations Reset subtask disclosure state within its session scope instead of keying the entire transcript before the stream message handoff. Cover the outgoing DOM lifecycle and disclosure reset with unit and browser regressions. Resolves NAN-396 * fix(webui): reset transcript UI on message ownership changes Keep the selected conversation separate from the owner of currently rendered messages. Reset the message subtree only when its owner changes, so cached and forked conversations get fresh UI state without remounting outgoing diffs. Extend the history-only caller and cover cached fork activity isolation while retaining the outgoing-DOM regression.
This commit is contained in:
1 parent
8b37976d36
commit
c1ed649b81
10 files changed
+165
-16
No files matched your search
@@ -43,23 +43,24 @@ function groupResults(messages: UIMessage[], tasks: ObservedSubagentTask[]) {
|
||||
|
||||
export function SubagentThreadMessages(props: ComponentProps<typeof ThreadMessages>) {
|
||||
const context = useSubagentTasks();
|
||||
return <ResultsThreadMessages key={context?.sessionKey} {...props} tasks={context?.tasks ?? []} />;
|
||||
}
|
||||
|
||||
function ResultsThreadMessages({ tasks, ...props }: ComponentProps<typeof ThreadMessages> & { tasks: ObservedSubagentTask[] }) {
|
||||
const groups = useMemo(() => groupResults(props.messages, tasks), [props.messages, tasks]);
|
||||
const [expandedTaskIds, setExpandedTaskIds] = useState<Set<string>>(() => new Set());
|
||||
const expanded = (results: ObservedSubagentTask[]) => results.some(task => expandedTaskIds.has(task.task_id));
|
||||
const sessionKey = context?.sessionKey;
|
||||
const groups = useMemo(() => groupResults(props.messages, context?.tasks ?? []), [props.messages, context?.tasks]);
|
||||
const [archive, setArchive] = useState(() => ({ sessionKey, expanded: new Set<string>() }));
|
||||
// Reset only the disclosures; the outgoing transcript must not remount during handoff.
|
||||
if (archive.sessionKey !== sessionKey) {
|
||||
setArchive({ sessionKey, expanded: new Set<string>() });
|
||||
}
|
||||
const expanded = (results: ObservedSubagentTask[]) => results.some(task => archive.expanded.has(task.task_id));
|
||||
const toggle = (results: ObservedSubagentTask[]) => {
|
||||
props.onActivityToggle?.();
|
||||
setExpandedTaskIds(current => {
|
||||
const next = new Set(current);
|
||||
const close = results.some(task => current.has(task.task_id));
|
||||
setArchive(current => {
|
||||
const next = new Set(current.expanded);
|
||||
const close = results.some(task => current.expanded.has(task.task_id));
|
||||
for (const task of results) {
|
||||
if (close) next.delete(task.task_id);
|
||||
else next.add(task.task_id);
|
||||
}
|
||||
return next;
|
||||
return { sessionKey, expanded: next };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -589,6 +589,7 @@ export function ThreadShell({
|
||||
}, [chatId, onTurnEnd]);
|
||||
const {
|
||||
messages,
|
||||
messagesKey,
|
||||
messagesReady,
|
||||
isStreaming,
|
||||
runStartedAt,
|
||||
@@ -1499,6 +1500,7 @@ export function ThreadShell({
|
||||
<ThreadViewport
|
||||
ref={viewportRef}
|
||||
messages={displayMessages}
|
||||
messagesKey={messagesKey}
|
||||
navigation={promptNavigation}
|
||||
navigationFrame={navigationFrame}
|
||||
temporary={temporary}
|
||||
|
||||
@@ -53,6 +53,8 @@ interface ThreadViewportProps {
|
||||
activeTurnId?: string | null;
|
||||
activeTurnStartedHere?: boolean;
|
||||
conversationKey?: string | null;
|
||||
/** Override when message ownership changes after the selected conversation. */
|
||||
messagesKey?: string | null;
|
||||
conversationReady?: boolean;
|
||||
showScrollToBottomButton?: boolean;
|
||||
cliApps?: CliAppInfo[];
|
||||
@@ -264,6 +266,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
activeTurnId: liveTurnId = null,
|
||||
activeTurnStartedHere = false,
|
||||
conversationKey = null,
|
||||
messagesKey = conversationKey,
|
||||
conversationReady = true,
|
||||
showScrollToBottomButton = true,
|
||||
cliApps = [],
|
||||
@@ -1192,6 +1195,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
<div ref={messageContentRef} className="w-full">
|
||||
<DiagramScope identity={conversationKey}>
|
||||
<SubagentThreadMessages
|
||||
key={messagesKey}
|
||||
messages={visibleMessages}
|
||||
topInset={PROMPT_TOP_INSET_PX}
|
||||
beforeUnit={retainedHistorySlotKey ? { key: retainedHistorySlotKey, content: (
|
||||
|
||||
Reference in new issue
Block a user