Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events and registered commands on TreeView are unreliable when refreshing treeview #153982

Open
FPtje opened this issue Jul 2, 2022 · 1 comment
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug tree-views Extension tree view issues
Milestone

Comments

@FPtje
Copy link

FPtje commented Jul 2, 2022

Does this issue occur when all extensions are disabled?: No/unknown, because I need an extension to show the behavior in the first place.

  • VS Code Version: vscode-1.68.1
  • OS Version: NixOS, with nixpkgs at revision 95e79164be1f7d883ed9ffda8b7d4ad3a17e6c1e. Also seen with Ubuntu 20.04.

Steps to Reproduce:

  • Create an extension with a tree view as per the basic instructions at https://code.visualstudio.com/api/extension-guides/tree-view
  • Refresh the tree very often, by using some function like this (this makes it easier to reproduce):
    async function refreshVeryOften(provider: NodeDependenciesProvider) {
        while (true) {
            await new Promise(f => setTimeout(f, 10)); // Wait 10ms, or some other small amount of time
            provider._onDidChangeTreeData.fire();
        }
    }
  • Register some view actions, as per https://code.visualstudio.com/api/extension-guides/tree-view#view-actions
    • Let's say we add the nodeDependencies.editEntry command and add it to the view/item/context, as per the example.
  • Register an onDidExpandElement and onDidCollapseElement listener that just run console.log. e.g.:
    treeView.onDidExpandElement(event => console.log("onDidExpandElement", event));
    treeView.onDidCollapseElement(event => console.log("onDidCollapseElement", event));
  • Start VS Code with the extension
  • Try to run the added view action a couple of times
  • Try to expand/collapse some tree items. It might take some times to reproduce

Expected results

Despite the refreshes, I would expect the onDidExpandElement and onDidCollapseElement listeners to run and console.log the event. I would also expect the nodeDependencies.editEntry command to always run, and the function is passed a TreeItem.

Actual result

  • onDidExpandElement often does not get called, even though in the UI, I see that the tree view item is expanded
  • onDidCollapseElement often does not get called, even though in the UI, I see that the tree view item is collapsed
  • The nodeDependencies.editEntry registered command sometimes gets called with no arguments, i.e. no TreeItem is passed.

Video example

This is in a different project, namely my Semaphore CI extension. Note that I have set the refresh delay to 2 seconds (2000ms).

reproduce-buttonpress

Same for collapsing/expanding events. In the video you can see the element being expanded and collapsed, but not every change in the UI is shown in the events.
collapsing

Speculated cause

I think some part of the tree view is removed before the new one is finished rendering, during a refresh. Either way it seems like some race/timing condition, because it sometimes happens and sometimes doesn't, even though the code path on the extension side should be exactly the same.

@dbaeumer dbaeumer assigned sandy081 and unassigned dbaeumer Jul 4, 2022
@sandy081 sandy081 assigned alexr00 and unassigned sandy081 Jul 4, 2022
@alexr00 alexr00 added bug Issue identified by VS Code Team member as probable bug tree-views Extension tree view issues labels Jul 4, 2022
@alexr00 alexr00 added this to the On Deck milestone Jul 4, 2022
@alexr00
Copy link
Member

alexr00 commented Jul 4, 2022

I think some part of the tree view is removed before the new one is finished rendering, during a refresh.

When I investigated this before, I saw that this is exactly what happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug tree-views Extension tree view issues
Projects
None yet
Development

No branches or pull requests

5 participants