Skip to content

Commit 247c906

Browse files
committed
fix(webview): clear durable view state on reset broadcast
1 parent 2861bf8 commit 247c906

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/core/webview/ClineProvider.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,15 +3057,17 @@ export class ClineProvider
30573057
}
30583058

30593059
/**
3060-
* Broadcast a reset event to all other live ClineProvider instances, clearing their
3061-
* view-local state caches and posting updated state so parallel tabs stay in sync.
3062-
* Also exposed for use by importSettingsWithFeedback (via broadcastResetToAllInstances callback).
3060+
* Broadcast a reset/import invalidation to all live ClineProvider instances, clearing
3061+
* both in-memory view-local caches and durable per-view selections so stale view state
3062+
* cannot mask imported/reset shared state after reload.
30633063
*/
30643064
async broadcastResetToAllInstances(): Promise<void> {
30653065
const allInstances = ClineProvider.getAllInstances()
30663066
for (const instance of allInstances) {
3067+
instance._clearViewLocalState()
3068+
await instance.contextProxy.setValue("viewStates", undefined)
3069+
30673070
if (instance !== this) {
3068-
instance._clearViewLocalState()
30693071
await instance.postStateToWebview()
30703072
}
30713073
}
@@ -3102,8 +3104,7 @@ export class ClineProvider
31023104
await this.customModesManager.resetCustomModes()
31033105
await this.removeClineFromStack()
31043106

3105-
// Clear this instance and all other live instances so parallel tabs don't keep stale state.
3106-
this._clearViewLocalState()
3107+
// Clear durable and in-memory per-view state across live instances so parallel tabs don't keep stale state.
31073108
await this.broadcastResetToAllInstances()
31083109

31093110
await this.postStateToWebview()

src/core/webview/__tests__/ClineProvider.parallelMode.spec.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,10 @@ describe("ClineProvider - Parallel Mode Support", () => {
10951095

10961096
await provider1.broadcastResetToAllInstances()
10971097

1098-
expect((provider1 as any).viewLocalState.mode).toBe("architect")
1098+
expect((provider1 as any).viewLocalState).toEqual({})
10991099
expect((provider2 as any).viewLocalState).toEqual({})
1100+
expect(provider1.contextProxy.getValue("viewStates" as any)).toBeUndefined()
1101+
expect(provider2.contextProxy.getValue("viewStates" as any)).toBeUndefined()
11001102
expect(postStateToWebview2).toHaveBeenCalledTimes(1)
11011103

11021104
await provider1.dispose()
@@ -1111,7 +1113,8 @@ describe("ClineProvider - Parallel Mode Support", () => {
11111113

11121114
await provider.broadcastResetToAllInstances()
11131115

1114-
expect((provider as any).viewLocalState.mode).toBe("architect")
1116+
expect((provider as any).viewLocalState).toEqual({})
1117+
expect(provider.contextProxy.getValue("viewStates" as any)).toBeUndefined()
11151118
expect(postStateToWebview).not.toHaveBeenCalled()
11161119

11171120
await provider.dispose()
@@ -1136,9 +1139,12 @@ describe("ClineProvider - Parallel Mode Support", () => {
11361139

11371140
await provider1.broadcastResetToAllInstances()
11381141

1139-
expect((provider1 as any).viewLocalState.mode).toBe("code")
1142+
expect((provider1 as any).viewLocalState).toEqual({})
11401143
expect((provider2 as any).viewLocalState).toEqual({})
11411144
expect((provider3 as any).viewLocalState).toEqual({})
1145+
expect(provider1.contextProxy.getValue("viewStates" as any)).toBeUndefined()
1146+
expect(provider2.contextProxy.getValue("viewStates" as any)).toBeUndefined()
1147+
expect(provider3.contextProxy.getValue("viewStates" as any)).toBeUndefined()
11421148
expect(postStateToWebview1).not.toHaveBeenCalled()
11431149
expect(postStateToWebview2).toHaveBeenCalledTimes(1)
11441150
expect(postStateToWebview3).toHaveBeenCalledTimes(1)
@@ -1171,6 +1177,8 @@ describe("ClineProvider - Parallel Mode Support", () => {
11711177

11721178
expect((provider1 as any).viewLocalState).toEqual({})
11731179
expect((provider2 as any).viewLocalState).toEqual({})
1180+
expect(provider1.contextProxy.getValue("viewStates" as any)).toBeUndefined()
1181+
expect(provider2.contextProxy.getValue("viewStates" as any)).toBeUndefined()
11741182
expect((provider1.contextProxy as any).resetAllState).toHaveBeenCalledTimes(1)
11751183
expect((provider1.providerSettingsManager as any).resetAllConfigs).toHaveBeenCalledTimes(1)
11761184
expect((provider1.customModesManager as any).resetCustomModes).toHaveBeenCalledTimes(1)

0 commit comments

Comments
 (0)