Skip to content

[ENHANCEMENT] Dispose view listeners and ignore stale views when the webview is replaced #2205

Closed

Description

@edelauna

Problem (one or two sentences)

When the sidebar view is replaced, the old view keeps its listeners. A stale view can still dispatch messages and refresh provider state. This work comes from the review of PR #1715.

Context (who is affected and when)

ClineProvider.resolveWebviewView pushes the message, visibility, configuration and dispose listeners into long-lived lists. It does not dispose them when VS Code resolves a new view. A disposed view can also clear listeners that belong to the new view.

A resolve that is still waiting for its HTML can finish after the provider or view is gone. It then installs listeners on a view that no longer exists.

This is a prerequisite for the heartbeat watchdog in PR #1715. The watchdog needs a replaced view to stop refreshing the provider-wide heartbeat.

Desired behavior (conceptual, not technical)

  1. Keep the subscriptions of the current view in one list. Dispose that list when a different view replaces it, and when the view is disposed.
  2. Ignore events from a view that is no longer the current view. This applies to the message, visibility, configuration and dispose listeners.
  3. Stop a resolve that finishes after disposal or replacement. It must not assign HTML or install listeners.
  4. Clear this.view when the sidebar view is disposed.
  5. Add a test for each stale-resolve guard. This includes the guard after await this.getState(), which no test reaches today.

Constraints / preferences (optional)

Request checklist

  • I searched the existing Issues and Discussions for duplicates
  • This describes a specific problem with clear context and impact

Activity

  1. SoccerField24x7 commented on Oct 27, 2026

    @SoccerField24x7
    Contributor

    @edelauna I can take a stab at this if you don't already have someone tagged for it.

  2. edelauna commented on Oct 27, 2026

    @edelauna
    ContributorAuthor

    Thanks @SoccerField24x7 I had started it - but got distracted before pushing a branch.

  3. self-assigned this
    on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions