Change:
assert.deepStrictEqual(Array.from(container.querySelectorAll('.monaco-list-row')).map(e => e.textContent), ['a', 'b2']); }); <ins> test('issue #121567', async () => { const container = document.createElement('div'); const calls: Element[] = []; const dataSource = new class implements IAsyncDataSource<Element, Element> { hasChildren(element: Element): boolean { return !!element.children && element.children.length > 0; } async getChildren(element: Element) { calls.push(element); return element.children ?? Iterable.empty(); } }; const model = new Model({ id: 'root', children: [{ id: 'a', children: [{ id: 'aa' }] }] }); const a = model.get('a'); const tree = new AsyncDataTree<Element, Element>('test', container, new VirtualDelegate(), [new Renderer()], dataSource, { identityProvider: new IdentityProvider() }); tree.layout(200); await tree.setInput(model.root); assert.strictEqual(calls.length, 1, 'There should be a single getChildren call for the root'); assert(tree.isCollapsible(a), 'a is collapsible'); assert(tree.isCollapsed(a), 'a is collapsed'); await tree.updateChildren(a, false); assert.strictEqual(calls.length, 1, 'There should be no changes to the calls list, since a was collapsed'); assert(tree.isCollapsible(a), 'a is collapsible'); assert(tree.isCollapsed(a), 'a is collapsed'); const children = a.children; a.children = []; await tree.updateChildren(a, false); assert.strictEqual(calls.length, 1, 'There should still be no changes to the calls list, since a was collapsed'); assert(!tree.isCollapsible(a), 'a is no longer collapsible'); assert(tree.isCollapsed(a), 'a is collapsed'); a.children = children; await tree.updateChildren(a, false); assert.strictEqual(calls.length, 1, 'There should still be no changes to the calls list, since a was collapsed'); assert(tree.isCollapsible(a), 'a is collapsible again'); assert(tree.isCollapsed(a), 'a is collapsed'); await tree.expand(a); assert.strictEqual(calls.length, 2, 'Finally, there should be a getChildren call for a'); assert(tree.isCollapsible(a), 'a is still collapsible'); assert(!tree.isCollapsed(a), 'a is expanded'); }); </ins> });

Discussion:
If you "refresh" an item (with children) by calling and the item is not expanded, the method still gets called. should not be called until the item is expanded, otherwise potentially expensive operations can be run for no visible reason (since the children are hidden).
This could result in unexpected behavior. If an extension currently relies on to always update the children then there would be out-of-date tree items.
How would this result in unexpected behavior? If the tree item has not loaded its children, why should calling refresh on it force its children to load?
I'm concerned that some extension authors have come to depend on the current behavior to keep their internal tree structure updated. I suppose we can try it and see if there are any complaints.
I think a change like this would need to happen in the , as at the custom tree view level we have no knowledge of whether a node is currently expanded or not. Is this something you'd be interested in doing?
Not sure I follow. What describes is exactly how the AsyncDataTree works: children aren't resolved until the user expands the parent the first time.
I am looking for a way to call on the AsyncDataTree such that if the tree item passed in to is collapsed, it will: "invalidate" the children or the tree item and not actually call on that tree item rerender the tree item instead of: calling for the tree item rerendering the tree item
Oh I guess I was wrong, what I said only applies to the next level. But the first node is called with will always have its be called. We can maybe add an option here, or even change the default behavior as I see no reason for collapsed tree nodes to need a call.
any update here? This issue causes GitLens to request way more data than desired in multiple cases (before the user expands them that is).
Thank you!
Thanks for the nudge!
Maybe it's easier if you verify this one.
will verify.
FYI, I tested GitLens with this change (in today's insiders) and it looks good to me!