Skip to content

Commit 2fad561

Browse files
committed
fix: dispose view using .dispose
1 parent 0ca60dd commit 2fad561

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/activate/__tests__/registerCommands.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe("getVisibleProviderOrLog", () => {
5555

5656
expect(result).toBeUndefined()
5757
expect(mockOutputChannel.appendLine).toHaveBeenCalledWith(
58-
"Cannot find any active and visible Roo Code provider instances.",
58+
"Cannot find any active and visible Roo Code provider instance.",
5959
)
6060
})
6161
})

src/core/webview/ClineProvider.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,17 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
446446
}
447447
// For tab panels, their onDidDispose is handled where they are created
448448
// (see: openClineInNewTab, which calls setPanel(undefined, "tab"))
449-
this.view = undefined
449+
if ("dispose" in this.view) {
450+
this.view.dispose()
451+
}
450452
this.log("Cleared this.view reference due to webview disposal.")
451453
}
452454
// Do NOT call this.dispose() for the provider instance here.
453455
// Provider-level disposables are managed by the main dispose() method.
454456
// This should only handle the disposal of the webview view itself.
455457
},
456458
null,
457-
this.context.subscriptions,
459+
this.disposables,
458460
)
459461

460462
// Listen for when color changes
@@ -581,13 +583,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
581583
}
582584

583585
public async postMessageToWebview(message: ExtensionMessage) {
584-
if (this.view && this.view.webview) {
585-
await this.view.webview.postMessage(message)
586-
} else {
587-
this.outputChannel.appendLine(
588-
`Cannot post message to webview (${this.viewType}): Webview is not available. Message type: ${message.type}`,
589-
)
590-
}
586+
await this.view?.webview.postMessage(message)
591587
}
592588

593589
private async getHMRHtmlContent(webview: vscode.Webview): Promise<string> {

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ jest.mock("../../../integrations/misc/extract-text", () => ({
227227
}),
228228
}))
229229

230+
jest.mock("../../../activate/registerCommands.ts", () => ({
231+
getPanel: jest.fn(),
232+
setPanel: jest.fn(),
233+
}))
234+
230235
afterAll(() => {
231236
jest.restoreAllMocks()
232237
})
@@ -310,6 +315,9 @@ describe("ClineProvider", () => {
310315
onDidChangeVisibility: jest.fn().mockImplementation(() => ({ dispose: jest.fn() })),
311316
} as unknown as vscode.WebviewView
312317

318+
const { getPanel } = require("../../../activate/registerCommands")
319+
;(getPanel as jest.Mock).mockReturnValue(mockWebviewView)
320+
313321
provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
314322

315323
defaultTaskOptions = {

0 commit comments

Comments
 (0)