Skip to content

Commit a81e24e

Browse files
fix(webview): load persisted selections when a view id is registered
1 parent 4124c43 commit a81e24e

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

‎src/core/webview/ClineProvider.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,10 @@ export class ClineProvider
891891
if (adoptedClaim) {
892892
this.postViewStateClaimToWebview(this.viewStateId, adoptedClaim)
893893
}
894+
895+
// Registration is only complete once the view's own persisted selections are in the
896+
// buffer; nothing else loads them now that reset/import handling lives downstream.
897+
await this.loadViewState()
894898
} catch (error) {
895899
// A persistence failure must not leave the provider holding an id that was
896900
// never registered: restore the previous id so a later launch retries the
@@ -5243,15 +5247,6 @@ export class ClineProvider
52435247
}
52445248
}
52455249

5246-
/**
5247-
* Clear view-local state cache so that getState() falls back to ContextProxy defaults.
5248-
*/
5249-
private _clearViewLocalState(): void {
5250-
this.viewLocalState = {}
5251-
// Load initial state from global state into viewLocalState buffer after dependencies used by getState are ready.
5252-
void this.loadViewState()
5253-
}
5254-
52555250
/** Load non-secret persisted selections; in-flight buffer edits are reapplied on top. */
52565251
private async loadViewState(): Promise<void> {
52575252
// Capture the id this load is for: a newer id registered while an async

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3601,6 +3601,29 @@ describe("ClineProvider", () => {
36013601
await provider.dispose()
36023602
})
36033603

3604+
it("loads the persisted selections of the registered view", async () => {
3605+
const provider = new ClineProvider(
3606+
mockContext,
3607+
mockOutputChannel,
3608+
"sidebar",
3609+
new ContextProxy(mockContext),
3610+
new WebviewFocusTracker(),
3611+
)
3612+
await provider.contextProxy.setValue("viewStates", {
3613+
"stable-view": { claimToken: "host-token", mode: "architect", currentApiConfigName: "cfg-a" },
3614+
})
3615+
const logSpy = vi.spyOn(provider, "log")
3616+
3617+
await provider["setViewStateId"]("stable-view", "host-token")
3618+
3619+
// Registration is what loads a view's own selections: the buffer is populated and
3620+
// the load is logged, so a reload restores the pinned mode instead of the shared one.
3621+
expect(provider["viewLocalState"].mode).toBe("architect")
3622+
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Loaded state for viewId"))
3623+
3624+
await provider.dispose()
3625+
})
3626+
36043627
it("restores the previous view id when the registration write fails so a later launch retries", async () => {
36053628
const contextProxy = new ContextProxy(mockContext)
36063629
const provider = new ClineProvider(

0 commit comments

Comments
 (0)