Compare commits

...
Author SHA1 Message Date
Cursor AgentandJulius Marminge 0381ec7e53 perf(web): avoid visit writes during thread streaming
Co-authored-by: Julius Marminge <[email protected]>
2026-07-17 16:47:42 +00:00
2 changed files with 21 additions and 23 deletions

No files matched your search

+4 -23
View File
@@ -93,7 +93,6 @@ import {
togglePendingUserInputOptionSelection,
type PendingUserInputDraftAnswer,
} from "../pendingUserInput";
import { useUiStateStore } from "../uiStateStore";
import {
buildPlanImplementationThreadTitle,
buildPlanImplementationPrompt,
@@ -109,6 +108,7 @@ import {
type Thread,
type TurnDiffSummary,
} from "../types";
import { useMarkActiveThreadVisited } from "../hooks/useMarkActiveThreadVisited";
import { useTheme } from "../hooks/useTheme";
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
import { isCommandPaletteOpen } from "../commandPaletteContext";
@@ -1036,9 +1036,9 @@ function ChatViewContent(props: ChatViewProps) {
const composerDraftTarget: ScopedThreadRef | DraftId =
routeKind === "server" ? routeThreadRef : props.draftId;
const serverThread = useThread(routeKind === "server" ? routeThreadRef : null);
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
const activeThreadLastVisitedAt = useUiStateStore((store) =>
routeKind === "server" ? store.threadLastVisitedAtById[routeThreadKey] : undefined,
useMarkActiveThreadVisited(
routeKind === "server" ? routeThreadKey : null,
serverThread?.latestTurn?.completedAt ?? null,
);
const settings = useEnvironmentSettings(environmentId);
const setStickyComposerModelSelection = useComposerDraftStore(
@@ -1599,25 +1599,6 @@ function ChatViewContent(props: ChatViewProps) {
[openOrReuseProjectDraftThread],
);
useEffect(() => {
if (!serverThread?.id) return;
const threadUpdatedAt = Date.parse(serverThread.updatedAt);
if (Number.isNaN(threadUpdatedAt)) return;
const lastVisitedAt = activeThreadLastVisitedAt ? Date.parse(activeThreadLastVisitedAt) : NaN;
if (!Number.isNaN(lastVisitedAt) && lastVisitedAt >= threadUpdatedAt) return;
markThreadVisited(
scopedThreadKey(scopeThreadRef(serverThread.environmentId, serverThread.id)),
serverThread.updatedAt,
);
}, [
activeThreadLastVisitedAt,
markThreadVisited,
serverThread?.environmentId,
serverThread?.id,
serverThread?.updatedAt,
]);
const selectedProviderByThreadId = composerActiveProvider ?? null;
const threadProvider =
activeThread?.modelSelection.instanceId ??
@@ -0,0 +1,17 @@
import { useEffect } from "react";
import { useUiStateStore } from "../uiStateStore";
export function useMarkActiveThreadVisited(
threadKey: string | null,
latestTurnCompletedAt: string | null,
): void {
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
useEffect(() => {
if (threadKey === null || latestTurnCompletedAt === null) {
return;
}
markThreadVisited(threadKey, latestTurnCompletedAt);
}, [latestTurnCompletedAt, markThreadVisited, threadKey]);
}