Compare commits

...
Author SHA1 Message Date
Cursor Agent 35f57d0519 Fix sync effects firing on mount and thread upsert wiping turn diff summaries
- Add prevSyncedThreadIdRef to skip sync effects on mount and thread
  switch, preventing redundant server writes and race conditions
- Fix turnDiffSummaries in APPLY_STATE_EVENT to check .length before
  using payload value, since server always sends empty array
2026-02-20 02:17:14 +00:00
2 changed files with 13 additions and 3 deletions

No files matched your search

+10
View File
@@ -764,8 +764,11 @@ export default function ChatView({ threadId }: ChatViewProps) {
const hasReachedTerminalLimit =
(activeThread?.terminalIds.length ?? 0) >= MAX_THREAD_TERMINAL_COUNT;
const prevSyncedThreadIdRef = useRef<string | undefined>(undefined);
useEffect(() => {
if (!api || !activeThread) return;
if (prevSyncedThreadIdRef.current !== activeThread.id) return;
void api.threads
.updateTitle({
threadId: activeThread.id,
@@ -776,6 +779,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
useEffect(() => {
if (!api || !activeThread) return;
if (prevSyncedThreadIdRef.current !== activeThread.id) return;
void api.threads
.updateModel({
threadId: activeThread.id,
@@ -786,6 +790,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
useEffect(() => {
if (!api || !activeThread) return;
if (prevSyncedThreadIdRef.current !== activeThread.id) return;
void api.threads
.updateBranch({
threadId: activeThread.id,
@@ -797,6 +802,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
useEffect(() => {
if (!api || !activeThread) return;
if (prevSyncedThreadIdRef.current !== activeThread.id) return;
void api.threads
.updateTerminalState({
threadId: activeThread.id,
@@ -819,6 +825,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
api,
]);
useEffect(() => {
prevSyncedThreadIdRef.current = activeThread?.id;
}, [activeThread?.id]);
const revokePreviewUrls = useCallback((images: Array<{ previewUrl?: string }>) => {
for (const image of images) {
if (!image.previewUrl) continue;
+3 -3
View File
@@ -649,9 +649,9 @@ export function reducer(state: AppState, action: Action): AppState {
...(threadPayload as unknown as Omit<StateBootstrapThread, "messages">),
messages: existingStateMessages,
turnDiffSummaries:
(threadPayload?.turnDiffSummaries as Thread["turnDiffSummaries"] | undefined) ??
existing?.turnDiffSummaries ??
[],
(threadPayload?.turnDiffSummaries as Thread["turnDiffSummaries"] | undefined)?.length
? (threadPayload!.turnDiffSummaries as Thread["turnDiffSummaries"])
: (existing?.turnDiffSummaries ?? []),
};
const nextThread = hydrateThreadFromBootstrap(bootstrapThread, existing);
const nextThreads = existing