Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/mcp-server/src/tui/dashboard-app.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ describe('DashboardApp', () => {
expect(frame).not.toContain('/from-state');
});

it('memoizes now based on tick to avoid non-deterministic re-renders', () => {
const dateNowSpy = vi.spyOn(Date, 'now').mockReturnValue(1700000000000);

const state = createInitialDashboardState();
const { lastFrame, rerender } = render(<DashboardApp externalState={state} />);
const frame1 = lastFrame() ?? '';

// Advance Date.now() by 1 minute — but tick has NOT changed (still 0 from mock)
dateNowSpy.mockReturnValue(1700000060000);
rerender(<DashboardApp externalState={state} />);
const frame2 = lastFrame() ?? '';

// With useMemo([tick]): now stays cached → frames identical
// Without useMemo: now = Date.now() changes → time display differs
expect(frame1).toBe(frame2);

dateNowSpy.mockRestore();
});

it('should use externalState when provided (multi-session mode)', () => {
const mockState = createInitialDashboardState();
// Modify some fields to verify they propagate
Expand Down
2 changes: 1 addition & 1 deletion apps/mcp-server/src/tui/dashboard-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function DashboardApp({
}: DashboardAppProps): React.ReactElement {
const { columns, rows, layoutMode } = useTerminalSize();
const tick = useTick(1000);
const now = Date.now();
const now = useMemo(() => Date.now(), [tick]);
const internalState = useDashboardState(externalState ? undefined : eventBus);
const state = externalState ?? internalState;
const focusedAgent = state.focusedAgentId
Expand Down
Loading