Skip to content

Commit 19a1fdb

Browse files
author
easonLiangWorldedtech
committed
fix(webview): satisfy the merged ClineProvider contract
The merge with main made the focus tracker a required constructor argument and made getTaskHistoryItem() return undefined, which the compile job caught: - ClineProvider.spec.ts: every branch-added ClineProvider construction now passes a WebviewFocusTracker. - handleModeSwitchUnlocked: the history-write compensation now runs only when a history item existed before the switch, and re-reads the item before restoring the pre-switch mode. Previously it dereferenced a possibly undefined item both when capturing the previous mode and when spreading it into updateTaskHistory. Local: core/webview suite 699/699 green; eslint clean on both files with no suppression-count growth.
1 parent 5107d70 commit 19a1fdb

2 files changed

Lines changed: 540 additions & 76 deletions

File tree

‎src/core/webview/ClineProvider.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,11 +2117,21 @@ export class ClineProvider
21172117
// new mode while the provider state is still on the old one. Until then this
21182118
// is the compensation for the history write that just landed.
21192119
undoHistoryWrite = async () => {
2120+
if (!taskHistoryItem) {
2121+
// No history item existed before the switch, so no history write landed:
2122+
// there is nothing to undo.
2123+
return
2124+
}
2125+
const previousMode = taskHistoryItem.mode
21202126
// Restore only the field this switch changed: re-read the item so fields
21212127
// the running task persisted during the pending window (tokens, cost,
21222128
// status, apiConfigName) survive the rollback.
21232129
const latest = this.getTaskHistoryItem(task.taskId) ?? taskHistoryItem
2124-
await this.updateTaskHistory({ ...latest, mode: taskHistoryItem.mode })
2130+
if (!latest) {
2131+
// The item was removed while the write was in flight; nothing to restore.
2132+
return
2133+
}
2134+
await this.updateTaskHistory({ ...latest, mode: previousMode })
21252135
}
21262136
} catch (error) {
21272137
// If persistence fails, log the error but don't update the in-memory state.

0 commit comments

Comments
 (0)