fix(site): prevent stale title clobber in sidebar from watchChats race (#22734)

This commit is contained in:
Kyle Carberry
2026-03-06 14:42:49 -08:00
committed by GitHub
parent f404463317
commit 8c52e150f6
2 changed files with 24 additions and 16 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference path="./.next/types/routes.d.ts" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
+22 -15
View File
@@ -492,25 +492,32 @@ const AgentsPage: FC = () => {
return;
}
// Scope field updates by event kind so that
// status_change events (which may carry a stale title
// snapshot from before async title generation
// finished) don't clobber a title_change that already
// landed.
const isTitleEvent = chatEvent.kind === "title_change";
const isStatusEvent = chatEvent.kind === "status_change";
queryClient.setQueryData(
chatsKey,
(prev: TypesGen.Chat[] | undefined) => {
if (!prev) return prev;
const exists = prev.some((c) => c.id === updatedChat.id);
if (exists) {
return prev.map((c) =>
c.id === updatedChat.id
? {
...c,
status: updatedChat.status,
title: updatedChat.title,
updated_at:
c.updated_at > updatedChat.updated_at
? c.updated_at
: updatedChat.updated_at,
}
: c,
);
return prev.map((c) => {
if (c.id !== updatedChat.id) return c;
return {
...c,
...(isStatusEvent && { status: updatedChat.status }),
...(isTitleEvent && { title: updatedChat.title }),
updated_at:
c.updated_at > updatedChat.updated_at
? c.updated_at
: updatedChat.updated_at,
};
});
}
if (chatEvent.kind === "created") {
return [updatedChat, ...prev];
@@ -528,8 +535,8 @@ const AgentsPage: FC = () => {
...previousChat,
chat: {
...previousChat.chat,
status: updatedChat.status,
title: updatedChat.title,
...(isStatusEvent && { status: updatedChat.status }),
...(isTitleEvent && { title: updatedChat.title }),
updated_at:
previousChat.chat.updated_at > updatedChat.updated_at
? previousChat.chat.updated_at