Implements
docs/plans/2026-07-22-001-fix-dashboard-remount-churn-plan.md: every
confirmed source of unnecessary unmount/remount churn in the dashboard,
plus a keep-alive layer for conversation- and terminal-bearing surfaces.
## What changed
**Keying / component identity (U1–U3)**
- Streaming chat segment key no longer embeds `entries.length` — an
expanded thinking block stays expanded while entries stream into it
(R1).
- Dock task list keys `TaskCard` rows by `task.id` (occurrence suffix
only for the duplicate-id anomaly) instead of `id-index` — no remount on
reorder/filter/status change (R2).
- `ProviderStatusBadge` / `GitHubStatusBadge` hoisted out of
ModelOnboardingModal's render body (R3); MCP server rows key by
`server.name` alone (R4).
**Keep-alive layer (U4–U6)**
- New shared `KeepAliveView` wrapper: visible = in-flow flex child;
hidden = out-of-flow `position:absolute; inset:0` with
`visibility:hidden; pointer-events:none` + `aria-hidden` (never
`display:none`, so xterm geometry never collapses).
- Planning Mode renders as a kept-alive sibling of the MainContent
switch after first open (per-project latch mirroring Quick Chat). While
hidden, the session-list SSE, recovery poll, and elapsed ticker suspend
via a new `active` prop; reveal re-subscribes and refreshes the sessions
list once. Payload-carrying entry points (initial-plan handoff, resume)
and project switches remount via a new
`modalManager.planningEntryGeneration` key, preserving pre-keep-alive
fresh-open semantics. `recordResumeEvent` instrumentation records
`remount` on first activation and `route-active` on reveal.
- Task-detail Terminal / Worktree-terminal / Planner-chat tabs stay
mounted-but-hidden after first open (per-task latches; task switch/close
still disposes fully). `SessionTerminal` gains `active`: reveal refits +
forces a font remeasure, and if the WS died while hidden it re-runs the
full attach lifecycle (dead-socket recovery).
- Popped-out task windows hide via FloatingWindow `hidden` instead of
leaving the render array; `TaskDetailContent` gains `active` so hidden
popups close their SSE/EventSource channels while the terminal WS stays
open. `visiblePoppedOutTaskEntries` remains the Escape-shortcut
consumer.
**Planning Mode internal-transition audit (U7)**
- Audit findings: session-list mode and mobile list/detail flips are
CSS-class transitions over one always-mounted detail pane (no
state-discarding unmounts); re-selecting the active session is an
early-return visibility restore; session switching intentionally reloads
from the session row (stream re-attach for generating sessions);
remaining index keys are on stateless lists. No product-code defects
found; regression tests now lock the always-mounted invariant on desktop
+ mobile.
**Cheap-view state (U8)**
- CommandCenter (active sub-tab + date range) and DevServerView
(selected script/task + typed-but-unsent command) persist per project
via `modalPersistence` and restore after their (intentional) unmount
round-trips. Also fixed the candidate auto-fill effect clobbering a
customized non-empty command.
## Symptom Verification
- **Original symptom:** streaming thinking blocks collapsed mid-stream;
terminals reconnected and lost scroll/input on tab flips; Planning Mode
lost in-flight interviews on navigation; popped-out windows vanished
off-view; dock cards remounted on reorder.
- **Exact reproduction:** (1) expand a thinking block during a stream;
(2) run a command in the Terminal tab, flip to Plan and back; (3) start
a planning interview, navigate Board and back; (4) pop out a task with
board/list-only scoping and switch views; (5) change a dock task's
status.
- **Assertion it is gone:** component-identity/instrumentation tests in
TaskChatTab, SessionTerminal, TaskDetailModal
(worktree/planner-chat/tabs), PlanningModeModal keep-alive +
internal-transitions, App keep-alive round-trip, and
App.taskPopupViewGating assert no remount and preserved state for each
repro, across desktop and mobile breakpoints.
## Verification
- File-scoped vitest: 23 files / 1091 tests green (all touched suites
plus FloatingWindow, TerminalModal, TaskPlannerChatTab,
lazy-loaded-views guard, App suites).
- `pnpm verify:fast`: PASS (13 steps — scoped typecheck/build, CLI
build, boot smoke).
- `pnpm check:changesets`: passes; changeset
`fix-dashboard-remount-churn` (`@runfusion/fusion` patch, labeled
format).
- Known pre-existing failures NOT caused by this branch (verified
failing at base a224c1111 in a clean worktree): 7 tests in
`TaskDetailModal.oversight-controls/oversight-mobile/models-progress-workflow`.
- jsdom cannot prove rendered-grid correctness for xterm reveal; per the
plan's risk note, manual browser verification of terminal reveal remains
recommended.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Switching views or tabs no longer resets Planning Mode, task details,
terminals, planner chats, or popped-out task windows.
* Streaming content remains expanded and stable as new entries arrive.
* Hidden views suspend background activity and resume correctly when
shown.
* Terminal sessions reconnect automatically when needed.
* **Improvements**
* Command Center and Dev Server selections persist per project.
* Custom Dev Server commands are preserved while browsing suggestions.
* Improved stability when reordering task lists and updating server
states.
* **Documentation**
* Updated dashboard guidance for hidden, retained task pop-ups and view
transitions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
295 lines
11 KiB
TypeScript
295 lines
11 KiB
TypeScript
import React from "react";
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
|
|
vi.mock("mermaid", () => ({
|
|
default: {
|
|
initialize: vi.fn(),
|
|
render: vi.fn().mockResolvedValue({ svg: "<svg data-testid='mock-mermaid-svg'></svg>" }),
|
|
},
|
|
}));
|
|
|
|
const mockEmbeddedTerminal = vi.fn((props: Record<string, unknown>) => (
|
|
<div data-testid="mock-worktree-terminal" data-props={JSON.stringify(props)} />
|
|
));
|
|
|
|
vi.mock("../TerminalModal", () => ({
|
|
TerminalModal: (props: Record<string, unknown>) => mockEmbeddedTerminal(props),
|
|
}));
|
|
|
|
import {
|
|
makeTask,
|
|
noop,
|
|
noopDelete,
|
|
noopMerge,
|
|
noopMove,
|
|
noopOpenDetail,
|
|
setupTaskDetailModalHooks,
|
|
} from "./TaskDetailModal.test-helpers";
|
|
import { TaskDetailModal, TaskDetailContent } from "../TaskDetailModal";
|
|
import * as dashboardApi from "../../api";
|
|
|
|
setupTaskDetailModalHooks();
|
|
|
|
function renderDetail(task = makeTask({ id: "FN-7813", worktree: "/repo/.worktrees/FN-7813" }), initialTab: "definition" | "worktree-terminal" = "definition") {
|
|
return render(
|
|
<TaskDetailModal
|
|
initialTab={initialTab}
|
|
task={task}
|
|
projectId="proj-123"
|
|
onClose={noop}
|
|
onMoveTask={noopMove}
|
|
onDeleteTask={noopDelete}
|
|
onMergeTask={noopMerge}
|
|
onOpenDetail={noopOpenDetail}
|
|
addToast={noop}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
describe("TaskDetailModal worktree terminal tab", () => {
|
|
beforeEach(() => {
|
|
mockEmbeddedTerminal.mockClear();
|
|
vi.spyOn(dashboardApi, "api").mockResolvedValue({ sessions: [] });
|
|
});
|
|
|
|
it("shows the interactive Terminal tab when a single-task worktree exists", async () => {
|
|
renderDetail();
|
|
|
|
expect(await screen.findByRole("button", { name: "Terminal" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the interactive Terminal tab when no worktree exists", async () => {
|
|
renderDetail(makeTask({ id: "FN-7813", worktree: undefined }));
|
|
|
|
expect(await screen.findByRole("button", { name: "Terminal" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the interactive Terminal tab for workspace tasks without a singular worktree", async () => {
|
|
renderDetail(makeTask({
|
|
id: "FN-7813",
|
|
worktree: undefined,
|
|
workspaceWorktrees: {
|
|
"packages/app": { worktreePath: "/repo/.worktrees/FN-7813-app", branch: "fusion/FN-7813-app" },
|
|
},
|
|
}));
|
|
|
|
expect(await screen.findByRole("button", { name: "Terminal" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("keeps the active Terminal tab visible when the worktree disappears and falls back to the project root", async () => {
|
|
const { rerender } = renderDetail(undefined, "worktree-terminal");
|
|
|
|
fireEvent.click(await screen.findByRole("button", { name: "Terminal" }));
|
|
expect(await screen.findByTestId("mock-worktree-terminal")).toBeInTheDocument();
|
|
|
|
rerender(
|
|
<TaskDetailModal
|
|
initialTab="worktree-terminal"
|
|
task={makeTask({ id: "FN-7813", worktree: undefined })}
|
|
projectId="proj-123"
|
|
onClose={noop}
|
|
onMoveTask={noopMove}
|
|
onDeleteTask={noopDelete}
|
|
onMergeTask={noopMerge}
|
|
onOpenDetail={noopOpenDetail}
|
|
addToast={noop}
|
|
/>,
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByRole("button", { name: "Terminal" })).toHaveClass("detail-tab-active");
|
|
expect(screen.getByTestId("mock-worktree-terminal")).toBeInTheDocument();
|
|
});
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
embedded: true,
|
|
isOpen: true,
|
|
defaultCwd: undefined,
|
|
scopeId: "FN-7813",
|
|
projectId: "proj-123",
|
|
}));
|
|
});
|
|
|
|
it("passes the task worktree and task-scoped namespace into embedded TerminalModal", async () => {
|
|
renderDetail(undefined, "worktree-terminal");
|
|
|
|
fireEvent.click(await screen.findByRole("button", { name: "Terminal" }));
|
|
await screen.findByTestId("mock-worktree-terminal");
|
|
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
embedded: true,
|
|
isOpen: true,
|
|
defaultCwd: "/repo/.worktrees/FN-7813",
|
|
scopeId: "FN-7813",
|
|
projectId: "proj-123",
|
|
}));
|
|
});
|
|
|
|
it("passes undefined cwd for no-worktree tasks so TerminalModal creates a project-root shell", async () => {
|
|
renderDetail(makeTask({ id: "FN-7826", worktree: undefined }), "worktree-terminal");
|
|
|
|
fireEvent.click(await screen.findByRole("button", { name: "Terminal" }));
|
|
await screen.findByTestId("mock-worktree-terminal");
|
|
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
embedded: true,
|
|
isOpen: true,
|
|
defaultCwd: undefined,
|
|
scopeId: "FN-7826",
|
|
projectId: "proj-123",
|
|
}));
|
|
});
|
|
|
|
it("passes undefined cwd for workspace tasks so TerminalModal creates a project-root shell", async () => {
|
|
renderDetail(makeTask({
|
|
id: "FN-7826",
|
|
worktree: undefined,
|
|
workspaceWorktrees: {
|
|
"packages/app": { worktreePath: "/repo/.worktrees/FN-7826-app", branch: "fusion/FN-7826-app" },
|
|
},
|
|
}), "worktree-terminal");
|
|
|
|
fireEvent.click(await screen.findByRole("button", { name: "Terminal" }));
|
|
await screen.findByTestId("mock-worktree-terminal");
|
|
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
embedded: true,
|
|
isOpen: true,
|
|
defaultCwd: undefined,
|
|
scopeId: "FN-7826",
|
|
projectId: "proj-123",
|
|
}));
|
|
});
|
|
|
|
it("orders Comments, Terminal, and Cost tabs together", async () => {
|
|
const { container } = renderDetail();
|
|
|
|
await screen.findByRole("button", { name: "Terminal" });
|
|
const tabLabels = Array.from(document.querySelectorAll<HTMLButtonElement>(".detail-tabs .detail-tab"))
|
|
.map((tab) => tab.textContent?.trim());
|
|
|
|
expect(tabLabels.indexOf("Comments")).toBeGreaterThanOrEqual(0);
|
|
expect(tabLabels.indexOf("Terminal")).toBeGreaterThan(tabLabels.indexOf("Comments"));
|
|
expect(tabLabels.indexOf("Cost")).toBe(tabLabels.indexOf("Terminal") + 1);
|
|
});
|
|
|
|
it("renders distinct Session and Terminal tab labels when an agent session exists", async () => {
|
|
vi.mocked(dashboardApi.api).mockResolvedValueOnce({
|
|
sessions: [{
|
|
id: "cli-1",
|
|
taskId: "FN-7813",
|
|
projectId: "proj-123",
|
|
adapterId: "claude-local",
|
|
agentState: "busy",
|
|
terminationReason: null,
|
|
autonomyPosture: null,
|
|
}],
|
|
});
|
|
|
|
renderDetail();
|
|
|
|
expect(await screen.findByRole("button", { name: "Session" })).toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: "Terminal" })).toBeInTheDocument();
|
|
});
|
|
|
|
/*
|
|
FNXC:TaskDetailTabKeepAlive 2026-07-22-13:05:
|
|
FN remount-churn fix R6/R10: the worktree Terminal tab body stays mounted-but-hidden across tab flips (no shell teardown), while a task switch still fully unmounts it.
|
|
*/
|
|
it("keeps the worktree terminal mounted-but-hidden across tab switches", async () => {
|
|
renderDetail(undefined, "worktree-terminal");
|
|
|
|
fireEvent.click(await screen.findByRole("button", { name: "Terminal" }));
|
|
expect(await screen.findByTestId("mock-worktree-terminal")).toBeInTheDocument();
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Plan" }));
|
|
// Mounted-but-hidden: the embedded terminal survives inside the aria-hidden keep-alive wrapper.
|
|
expect(screen.getByTestId("mock-worktree-terminal")).toBeInTheDocument();
|
|
expect(screen.getByTestId("worktree-terminal-keep-alive")).toHaveAttribute("aria-hidden", "true");
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Terminal" }));
|
|
expect(screen.getByTestId("mock-worktree-terminal")).toBeInTheDocument();
|
|
expect(screen.getByTestId("worktree-terminal-keep-alive")).not.toHaveAttribute("aria-hidden");
|
|
});
|
|
|
|
it("fully unmounts the kept-alive worktree terminal when the task changes", async () => {
|
|
const { rerender } = renderDetail(undefined, "worktree-terminal");
|
|
|
|
fireEvent.click(await screen.findByRole("button", { name: "Terminal" }));
|
|
expect(await screen.findByTestId("mock-worktree-terminal")).toBeInTheDocument();
|
|
|
|
// Hide the terminal behind another tab, then switch tasks: the per-task latch must reset.
|
|
fireEvent.click(screen.getByRole("button", { name: "Plan" }));
|
|
expect(screen.getByTestId("worktree-terminal-keep-alive")).toBeInTheDocument();
|
|
|
|
rerender(
|
|
<TaskDetailModal
|
|
task={makeTask({ id: "FN-OTHER", worktree: "/repo/.worktrees/FN-OTHER" })}
|
|
projectId="proj-123"
|
|
onClose={noop}
|
|
onMoveTask={noopMove}
|
|
onDeleteTask={noopDelete}
|
|
onMergeTask={noopMerge}
|
|
onOpenDetail={noopOpenDetail}
|
|
addToast={noop}
|
|
/>,
|
|
);
|
|
|
|
// Keep-alive is scoped to one open task: the latch resets on task switch, so the terminal disposes exactly as before.
|
|
await waitFor(() => {
|
|
expect(screen.queryByTestId("worktree-terminal-keep-alive")).toBeNull();
|
|
expect(screen.queryByTestId("mock-worktree-terminal")).toBeNull();
|
|
});
|
|
});
|
|
|
|
/*
|
|
FNXC:TaskPopupViewGating 2026-07-23-10:35:
|
|
FN remount-churn fix follow-up (PR #2420 review): the kept-alive worktree terminal keeps
|
|
isOpen=true (xterm + WS survive) but must receive active=false whenever it is not the front
|
|
surface — behind another tab, or inside a hidden off-view popup (TaskDetailContent active=false) —
|
|
so its viewport listeners, resize observers, and refit loops suspend.
|
|
*/
|
|
it("suspends the kept-alive worktree terminal (active=false, isOpen=true) behind another tab and resumes on return", async () => {
|
|
renderDetail(undefined, "worktree-terminal");
|
|
|
|
fireEvent.click(await screen.findByRole("button", { name: "Terminal" }));
|
|
await screen.findByTestId("mock-worktree-terminal");
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({ isOpen: true, active: true }));
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Plan" }));
|
|
expect(screen.getByTestId("mock-worktree-terminal")).toBeInTheDocument();
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({ isOpen: true, active: false }));
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Terminal" }));
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({ isOpen: true, active: true }));
|
|
});
|
|
|
|
it("suspends the worktree terminal while the whole detail is a hidden kept-alive popup", async () => {
|
|
const task = makeTask({ id: "FN-7813", worktree: "/repo/.worktrees/FN-7813" });
|
|
const contentProps = {
|
|
task,
|
|
projectId: "proj-123",
|
|
onMoveTask: noopMove,
|
|
onDeleteTask: noopDelete,
|
|
onMergeTask: noopMerge,
|
|
onOpenDetail: noopOpenDetail,
|
|
addToast: noop,
|
|
initialTab: "worktree-terminal" as const,
|
|
};
|
|
const { rerender } = render(<TaskDetailContent {...contentProps} active />);
|
|
|
|
fireEvent.click(await screen.findByRole("button", { name: "Terminal" }));
|
|
await screen.findByTestId("mock-worktree-terminal");
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({ isOpen: true, active: true }));
|
|
|
|
// Popup hidden on another view: terminal stays mounted with the WS-preserving isOpen=true, aux work suspended.
|
|
rerender(<TaskDetailContent {...contentProps} active={false} />);
|
|
expect(screen.getByTestId("mock-worktree-terminal")).toBeInTheDocument();
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({ isOpen: true, active: false }));
|
|
|
|
// Reveal resumes auxiliary work.
|
|
rerender(<TaskDetailContent {...contentProps} active />);
|
|
expect(mockEmbeddedTerminal).toHaveBeenLastCalledWith(expect.objectContaining({ isOpen: true, active: true }));
|
|
});
|
|
});
|