microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.88k stars 29.52k forks source link

Tab list gets corrupted when a new webview is opened (extension API) #228270

Open mmueller2012 opened 2 months ago

mmueller2012 commented 2 months ago

Does this issue occur when all extensions are disabled?: Yes

We develop an extension in which an existing tab gets replaced by a webview. We simply store a reference to the existing tab, open a webview and then close the original tab. This has worked fine up to version 1.89.1. On version >= 1.90.2 closing the tab using vscode.window.tabGroups.close fails with the exception Tab close: Invalid tab not found!. The tab has not been closed in the meantime nor did we get any close notifications for it via vscode.window.tabGroups.onDidChangeTabs.

Steps to Reproduce:

  1. Create an extension with the following function exposed as command:

    async dummy(): Promise<void> {
    const tab = vscode.window.tabGroups.activeTabGroup.activeTab;
    if (!tab) {
        console.log("Please open a tab to test this code.");
        return;
    }
    
    const panel = vscode.window.createWebviewPanel(
        "TestPanel",
        "Test",
        tab.group.viewColumn);
    panel.webview.html = "<body>Hello World</body>";
    
    // Introduce a tiny delay
    await panel.webview.postMessage("hello");
    
    vscode.window.tabGroups.close(tab);
    }
  2. Open some tab and call the command
  3. Check the debug console for the Tab close: Invalid tab not found! exception.
vs-code-engineering[bot] commented 2 months ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.93.0. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

mmueller2012 commented 2 months ago

I have tested it also with the newest insider build (1.94.0-insider / 6e9d8a281003211220a6732ec538a28c483ff78b) and the issue still remains.

bpasero commented 2 months ago

Bisect points to :https://github.com/microsoft/vscode/compare/3028408922e78cc9ca15ee761372a7c0603fa375...bbc4ba1eff648ee542972589216f211b7a6a08f2

I would guess it could be https://github.com/microsoft/vscode/commit/88bc75f68ce7940321c07d20f539cae61e7204af