修复右侧边栏diff区不实时显示修改文件

This commit is contained in:
xintaofei
2026-03-12 23:45:03 +08:00
parent a1d5a237e5
commit 0c54900396
3 changed files with 55 additions and 6 deletions

View File

@@ -137,7 +137,7 @@ const ConversationTabView = memo(function ConversationTabView({
const tWelcome = useTranslations("Folder.chat.welcomeInputPanel")
const sharedT = useTranslations("Folder.chat.shared")
const { folder, folderId, refreshConversations } = useFolderContext()
const { bindConversationTab } = useTabContext()
const { bindConversationTab, setTabRuntimeConversationId } = useTabContext()
const { setSessionStats } = useSessionStats()
const {
appendOptimisticTurn,
@@ -177,6 +177,19 @@ const ConversationTabView = memo(function ConversationTabView({
const canAutoConnect =
hasPersistedConversation || (agentsLoaded && usableAgentCount > 0)
// Expose the runtime session key to the tab so the aux panel (Diff sidebar)
// can look up live turns even before the DB conversation is created.
useEffect(() => {
if (effectiveConversationId !== conversationId) {
setTabRuntimeConversationId(tabId, effectiveConversationId)
}
}, [
tabId,
effectiveConversationId,
conversationId,
setTabRuntimeConversationId,
])
// Clear pendingCleanup when tab is (re)opened
useEffect(() => {
setPendingCleanup(effectiveConversationId, false)
@@ -544,7 +557,13 @@ const ConversationTabView = memo(function ConversationTabView({
}
setCreatedConversationId(newConversationId)
bindConversationTab(tabId, newConversationId, selectedAgent, title)
bindConversationTab(
tabId,
newConversationId,
selectedAgent,
title,
effectiveConversationId
)
moveMessageInputDraft(
buildNewConversationDraftStorageKey({ folderId }),
buildConversationDraftStorageKey(selectedAgent, newConversationId)

View File

@@ -265,7 +265,8 @@ export function SessionFilesTab() {
const { tabs, activeTabId } = useTabContext()
const activeTab = tabs.find((t) => t.id === activeTabId)
const conversationId = activeTab?.conversationId
const conversationId =
activeTab?.runtimeConversationId ?? activeTab?.conversationId
if (!activeTab) {
return (

View File

@@ -24,6 +24,10 @@ interface TabItemInternal {
id: string
kind: "conversation"
conversationId: number | null
/** The runtime session key used by ConversationRuntimeContext.
* For new conversations this is a virtual (negative) ID that differs
* from the persisted `conversationId`. */
runtimeConversationId?: number
agentType: AgentType
title: string
isPinned: boolean
@@ -55,7 +59,12 @@ interface TabContextValue {
tabId: string,
conversationId: number,
agentType: AgentType,
title: string
title: string,
runtimeConversationId?: number
) => void
setTabRuntimeConversationId: (
tabId: string,
runtimeConversationId: number
) => void
reorderTabs: (reorderedTabs: TabItem[]) => void
}
@@ -558,13 +567,20 @@ export function TabProvider({ children }: TabProviderProps) {
tabId: string,
conversationId: number,
agentType: AgentType,
title: string
title: string,
runtimeConversationId?: number
) => {
let nextActiveTabId: string | null = null
setTabs((prev) =>
prev.flatMap((tab) => {
if (tab.id === tabId) {
const nextTab = { ...tab, conversationId, agentType, title }
const nextTab = {
...tab,
conversationId,
agentType,
title,
runtimeConversationId,
}
return [nextTab]
}
@@ -594,6 +610,17 @@ export function TabProvider({ children }: TabProviderProps) {
[syncFolderContext]
)
const setTabRuntimeConversationId = useCallback(
(tabId: string, runtimeConversationId: number) => {
setTabs((prev) =>
prev.map((tab) =>
tab.id === tabId ? { ...tab, runtimeConversationId } : tab
)
)
},
[]
)
const value = useMemo(
() => ({
tabs,
@@ -609,6 +636,7 @@ export function TabProvider({ children }: TabProviderProps) {
toggleTileMode,
openNewConversationTab,
bindConversationTab,
setTabRuntimeConversationId,
reorderTabs,
}),
[
@@ -625,6 +653,7 @@ export function TabProvider({ children }: TabProviderProps) {
toggleTileMode,
openNewConversationTab,
bindConversationTab,
setTabRuntimeConversationId,
reorderTabs,
]
)