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.
This commit is contained in:
Cursor Agent committed 2026-03-30 20:48:50 +00:00
1 parent d32da3cb9a
commit 08e5181717
2 files changed
+8 -9

No files matched your search

+3 -2
View File
@@ -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", () => {
+5 -7
View File
@@ -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;
}