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:
chengyongru authored and GitHub committed 2026-11-02 17:42:16 +08:00
1 parent 8b37976d36
commit c1ed649b81
10 files changed
+165 -16

No files matched your search

+40 -2
View File
@@ -50,13 +50,14 @@ function emitTask(snapshot: SubagentTaskSnapshot) {
function ResultsPresence() {
return <output data-testid="has-results">{useHasSubagentResults() ? "yes" : "no"}</output>;
}
function layout({ threadMessages = messages, liveEvents = true, historyEnabled = false, onActivityToggle }: {
function layout({ threadMessages = messages, sessionKey = "websocket:a", liveEvents = true, historyEnabled = false, onActivityToggle }: {
threadMessages?: UIMessage[];
sessionKey?: string;
liveEvents?: boolean;
historyEnabled?: boolean;
onActivityToggle?: () => void;
} = {}) {
return <SubagentTasksProvider client={client} sessionKey="websocket:a" token="tok" enabled liveEvents={liveEvents} historyEnabled={historyEnabled}>
return <SubagentTasksProvider client={client} sessionKey={sessionKey} token="tok" enabled liveEvents={liveEvents} historyEnabled={historyEnabled}>
<ResultsPresence />
<div data-testid="messages"><SubagentThreadMessages messages={threadMessages} onActivityToggle={onActivityToggle} /></div>
<div data-testid="composer" className="thread-composer-stack"><SubagentTaskDock /><textarea aria-label="Message" /></div>
@@ -175,6 +176,43 @@ describe("subagent result archives", () => {
expect(requestMutation).not.toHaveBeenCalled();
});
it("resets task disclosures across sessions without remounting the outgoing transcript", async () => {
vi.mocked(fetch).mockImplementation(async (input) => response([
task(String(input).includes("websocket%3Ab") ? { task_id: "task-b", label: "Other check" } : {}),
]));
const user = userEvent.setup();
const view = render(layout());
const archive = await screen.findByRole("region", { name: "Subtasks" });
await user.click(summary(archive));
expect(summary(archive)).toHaveAttribute("aria-expanded", "true");
const outgoingPrompt = screen.getByText("Inspect config");
// The selected session changes before useNanobotStream hands over its messages.
view.rerender(layout({ sessionKey: "websocket:b" }));
expect(screen.getByText("Inspect config")).toBe(outgoingPrompt);
const other = await screen.findByRole("region", { name: "Subtasks" });
expect(summary(other)).toHaveAttribute("aria-expanded", "false");
await user.click(summary(other));
expect(within(other).getByRole("button", { name: "Other check Completed 4s" })).toBeVisible();
view.rerender(layout({ sessionKey: "websocket:b", threadMessages: [
{ ...messages[0], id: "prompt-b", content: "Other request" },
{ ...messages[1], id: "answer-b", content: "Other answer" },
] }));
expect(await screen.findByText("Other answer")).toBeVisible();
expect(summary(screen.getByRole("region", { name: "Subtasks" }))).toHaveAttribute("aria-expanded", "true");
view.rerender(layout());
const restored = await screen.findByRole("region", { name: "Subtasks" });
expect(summary(restored)).toHaveAttribute("aria-expanded", "false");
await user.click(summary(restored));
expect(within(restored).getByRole("button", { name: "Config check Completed 4s" })).toBeVisible();
view.rerender(layout({ sessionKey: "websocket:b" }));
expect(summary(await screen.findByRole("region", { name: "Subtasks" }))).toHaveAttribute("aria-expanded", "false");
view.rerender(layout());
expect(summary(await screen.findByRole("region", { name: "Subtasks" }))).toHaveAttribute("aria-expanded", "false");
});
it("prefers the exact initiating prompt and falls back once to the first user message of its turn", async () => {
vi.mocked(fetch).mockImplementation(async () => response([
task({ task_id: "exact", label: "Exact check", origin_message_id: "followup", created_at: 101 }),
@@ -1014,6 +1014,7 @@ describe("useNanobotStream", () => {
initialProps: { chatId: "chat-old" },
},
);
expect(result.current.messagesKey).toBe("chat-old");
act(() => {
fake.emit("chat-old", {
@@ -1024,6 +1025,7 @@ describe("useNanobotStream", () => {
});
rerender({ chatId: "chat-new" });
expect(result.current.messagesKey).toBe("chat-new");
act(() => {
fake.emit("chat-new", {
+2
View File
@@ -939,6 +939,7 @@ describe("useSessions", () => {
});
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.messages[0]?.id).toBe("selected-user");
expect(result.current.messagesKey).toBe("websocket:selected");
expect(result.current.hasMoreBefore).toBe(true);
expect(result.current.userMessageOffset).toBe(4);
expect(result.current.hasPendingToolCalls).toBe(true);
@@ -948,6 +949,7 @@ describe("useSessions", () => {
rerender({ sessionKey: null });
expect(result.current.messages).toEqual([]);
expect(result.current.messagesKey).toBeNull();
expect(result.current.loading).toBe(false);
expect(result.current.hasMoreBefore).toBe(false);
expect(result.current.userMessageOffset).toBe(0);