From 08e518171764a25386c09fc9da95222128caead0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 30 Mar 2026 20:48:50 +0000 Subject: [PATCH] Fix unpinned items being re-pinned on next server sync Toggle functions now store false instead of deleting keys, and syncProjects/syncThreads unconditionally store pinned state for all items. This prevents the nullish coalescing fallback from reaching stale persisted sets and re-pinning items that the user explicitly unpinned. --- apps/web/src/uiStateStore.test.ts | 5 +++-- apps/web/src/uiStateStore.ts | 12 +++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/web/src/uiStateStore.test.ts b/apps/web/src/uiStateStore.test.ts index c0b1f52f5d..bdd7e9f275 100644 --- a/apps/web/src/uiStateStore.test.ts +++ b/apps/web/src/uiStateStore.test.ts @@ -136,6 +136,7 @@ describe("uiStateStore pure functions", () => { ]); expect(next.projectPinnedById).toEqual({ + [oldProject1]: false, [recreatedProject2]: true, }); }); @@ -232,7 +233,7 @@ describe("uiStateStore pure functions", () => { const unpinned = toggleProjectPinned(pinned, project1); - expect(unpinned.projectPinnedById).toEqual({}); + expect(unpinned.projectPinnedById).toEqual({ [project1]: false }); }); it("toggleThreadPinned adds and removes pinned state", () => { @@ -243,7 +244,7 @@ describe("uiStateStore pure functions", () => { const unpinned = toggleThreadPinned(pinned, thread1); - expect(unpinned.threadPinnedById).toEqual({}); + expect(unpinned.threadPinnedById).toEqual({ [thread1]: false }); }); it("clearThreadUi removes visit state for deleted threads", () => { diff --git a/apps/web/src/uiStateStore.ts b/apps/web/src/uiStateStore.ts index c1370fcf91..8c3996af60 100644 --- a/apps/web/src/uiStateStore.ts +++ b/apps/web/src/uiStateStore.ts @@ -211,9 +211,7 @@ export function syncProjects(state: UiState, projects: readonly SyncProjectInput (previousProjectIdForCwd ? previousPinnedById[previousProjectIdForCwd] : undefined) ?? persistedPinnedProjectCwds.has(project.cwd); nextExpandedById[project.id] = expanded; - if (pinned) { - nextPinnedById[project.id] = true; - } + nextPinnedById[project.id] = pinned; return { id: project.id, cwd: project.cwd, @@ -307,8 +305,8 @@ export function syncThreads(state: UiState, threads: readonly SyncThreadInput[]) ) { nextThreadLastVisitedAtById[thread.id] = thread.seedVisitedAt; } - if (nextThreadPinnedById[thread.id] === undefined && persistedPinnedThreadIds.has(thread.id)) { - nextThreadPinnedById[thread.id] = true; + if (nextThreadPinnedById[thread.id] === undefined) { + nextThreadPinnedById[thread.id] = persistedPinnedThreadIds.has(thread.id); } } if ( @@ -388,7 +386,7 @@ export function clearThreadUi(state: UiState, threadId: ThreadId): UiState { export function toggleThreadPinned(state: UiState, threadId: ThreadId): UiState { const nextThreadPinnedById = { ...state.threadPinnedById }; if (nextThreadPinnedById[threadId]) { - delete nextThreadPinnedById[threadId]; + nextThreadPinnedById[threadId] = false; } else { nextThreadPinnedById[threadId] = true; } @@ -457,7 +455,7 @@ export function reorderProjects( export function toggleProjectPinned(state: UiState, projectId: ProjectId): UiState { const nextProjectPinnedById = { ...state.projectPinnedById }; if (nextProjectPinnedById[projectId]) { - delete nextProjectPinnedById[projectId]; + nextProjectPinnedById[projectId] = false; } else { nextProjectPinnedById[projectId] = true; }