Skip to content

Disposing a webview view when extension host is restarted #188257

@alexr00

Description

@alexr00
Member

Originally in microsoft/vscode-pull-request-github#4872 (comment)

Here is what I see happen:

  1. Open a folder
  2. Have an extension that creates a webview view
  3. Keep the webview view open
  4. Add a folder to the workspace, which causes the extension host to be restarted.
  5. The extension's deactivate gets called as expected. In deactivate the extension disposes of the webview view provider.
  6. With this dispose I would expect the webview view to hide, but it does not.

You can easily reproduce the above using the GitHub Pull Request extension with the steps linked from the original issue.

Activity

juancampa

juancampa commented on May 3, 2024

@juancampa

+1 on this. Our webview stays open but there's no one listening for messages so it just doesn't work. i.e. messages sent via postMessage don't go anywhere.

I'm wondering if anyone has come up with a work-around.

juancampa

juancampa commented on May 3, 2024

@juancampa

Our current workaround is to search for orphaned webviews during activate, and close/reopen them.

In case this could help others:

  const orphanedTabs = vscode.window.tabGroups.all
    .flatMap((tabGroup) => tabGroup.tabs)
    .filter((tab) => (tab.input as any)?.viewType.includes(<VIEW ID>));
  vscode.window.tabGroups.close(orphanedTabs);
  // ... reopen if needed
  
added
bugIssue identified by VS Code Team member as probable bug
help wantedIssues identified as good community contribution opportunities
webview-viewsWebview views in the sidebar and panel
on Jun 26, 2024
added this to the Backlog milestone on Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bughelp wantedIssues identified as good community contribution opportunitieswebview-viewsWebview views in the sidebar and panel

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @juancampa@mjbvz@alexr00

    Issue actions

      Disposing a webview view when extension host is restarted · Issue #188257 · microsoft/vscode