Skip to content

Commit 338af88

Browse files
committed
fix(webview): clear durable view state on reset broadcast
1 parent 00e1196 commit 338af88

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
@@ -1260,8 +1260,10 @@ describe("ClineProvider - Parallel Mode Support", () => {
12601260

12611261
await provider1.broadcastResetToAllInstances()
12621262

1263-
expect((provider1 as any).viewLocalState.mode).toBe("architect")
1263+
expect((provider1 as any).viewLocalState).toEqual({})
12641264
expect((provider2 as any).viewLocalState).toEqual({})
1265+
expect(provider1.contextProxy.getValue("viewStates" as any)).toBeUndefined()
1266+
expect(provider2.contextProxy.getValue("viewStates" as any)).toBeUndefined()
12651267
expect(postStateToWebview2).toHaveBeenCalledTimes(1)
12661268

12671269
await provider1.dispose()
@@ -1276,7 +1278,8 @@ describe("ClineProvider - Parallel Mode Support", () => {
12761278

12771279
await provider.broadcastResetToAllInstances()
12781280

1279-
expect((provider as any).viewLocalState.mode).toBe("architect")
1281+
expect((provider as any).viewLocalState).toEqual({})
1282+
expect(provider.contextProxy.getValue("viewStates" as any)).toBeUndefined()
12801283
expect(postStateToWebview).not.toHaveBeenCalled()
12811284

12821285
await provider.dispose()
@@ -1301,9 +1304,12 @@ describe("ClineProvider - Parallel Mode Support", () => {
13011304

13021305
await provider1.broadcastResetToAllInstances()
13031306

1304-
expect((provider1 as any).viewLocalState.mode).toBe("code")
1307+
expect((provider1 as any).viewLocalState).toEqual({})
13051308
expect((provider2 as any).viewLocalState).toEqual({})
13061309
expect((provider3 as any).viewLocalState).toEqual({})
1310+
expect(provider1.contextProxy.getValue("viewStates" as any)).toBeUndefined()
1311+
expect(provider2.contextProxy.getValue("viewStates" as any)).toBeUndefined()
1312+
expect(provider3.contextProxy.getValue("viewStates" as any)).toBeUndefined()
13071313
expect(postStateToWebview1).not.toHaveBeenCalled()
13081314
expect(postStateToWebview2).toHaveBeenCalledTimes(1)
13091315
expect(postStateToWebview3).toHaveBeenCalledTimes(1)
@@ -1336,6 +1342,8 @@ describe("ClineProvider - Parallel Mode Support", () => {
13361342

13371343
expect((provider1 as any).viewLocalState).toEqual({})
13381344
expect((provider2 as any).viewLocalState).toEqual({})
1345+
expect(provider1.contextProxy.getValue("viewStates" as any)).toBeUndefined()
1346+
expect(provider2.contextProxy.getValue("viewStates" as any)).toBeUndefined()
13391347
expect((provider1.contextProxy as any).resetAllState).toHaveBeenCalledTimes(1)
13401348
expect((provider1.providerSettingsManager as any).resetAllConfigs).toHaveBeenCalledTimes(1)
13411349
expect((provider1.customModesManager as any).resetCustomModes).toHaveBeenCalledTimes(1)

0 commit comments

Comments
 (0)