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
This commit is contained in:
1 parent
1332c488ad
commit
35f57d0519
2 files changed
+13
-3
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user