Skip to content
Open
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
16 changes: 15 additions & 1 deletion apps/web/src/uiStateStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe("uiStateStore pure functions", () => {
expect(next.projectExpandedById[nextLogicalKey]).toBe(false);
});

it("syncThreads prunes missing thread UI state", () => {
it("syncThreads keeps visited state when transient snapshots omit a thread", () => {
const thread1 = ThreadId.make("thread-1");
const thread2 = ThreadId.make("thread-2");
const initialState = makeUiState({
Expand All @@ -358,6 +358,7 @@ describe("uiStateStore pure functions", () => {

expect(next.threadLastVisitedAtById).toEqual({
[thread1]: "2026-02-25T12:35:00.000Z",
[thread2]: "2026-02-25T12:36:00.000Z",
});
expect(next.threadChangedFilesExpandedById).toEqual({
[thread1]: {
Expand All @@ -366,6 +367,19 @@ describe("uiStateStore pure functions", () => {
});
});

it("syncThreads keeps markThreadVisited idempotent after partial snapshots", () => {
const thread1 = ThreadId.make("thread-1");
const completedAt = "2026-02-25T12:35:00.000Z";
const visitedState = markThreadVisited(makeUiState(), thread1, completedAt);

const afterPartialSnapshot = syncThreads(visitedState, []);

expect(afterPartialSnapshot.threadLastVisitedAtById[thread1]).toBe(completedAt);
expect(markThreadVisited(afterPartialSnapshot, thread1, completedAt)).toBe(
afterPartialSnapshot,
);
});

it("syncThreads seeds visit state for unseen snapshot threads", () => {
const thread1 = ThreadId.make("thread-1");
const initialState = makeUiState();
Expand Down
6 changes: 1 addition & 5 deletions apps/web/src/uiStateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,7 @@ export function syncProjects(state: UiState, projects: readonly SyncProjectInput

export function syncThreads(state: UiState, threads: readonly SyncThreadInput[]): UiState {
const retainedThreadIds = new Set(threads.map((thread) => thread.key));
const nextThreadLastVisitedAtById = Object.fromEntries(
Object.entries(state.threadLastVisitedAtById).filter(([threadId]) =>
retainedThreadIds.has(threadId),
),
);
const nextThreadLastVisitedAtById = { ...state.threadLastVisitedAtById };
for (const thread of threads) {
if (
nextThreadLastVisitedAtById[thread.key] === undefined &&
Expand Down
Loading