You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(overlay): walkAngularTree() drops nested child components inside HTML wrapper elements #11
In packages/ng-devtools/src/overlay.ts, walkAngularTree() traverses the DOM to build the live component hierarchy. However, the traversal immediately exits (if (!component) return;) whenever an element is not an Angular component host.
Because standard Angular templates wrap nested child components inside common HTML layout elements (such as <div class="container">, <main>, <section>, or <ul>), ng.getComponent() on those wrapper elements returns null. This causes walkAngularTree() to abort recursion prematurely, dropping all nested child components from the DevTools Component Tree and the MCP ng-devtools:component-tree agent resource.
functionwalkAngularTree(el: Element,out: ComponentTreeNode[],ng: any){constcomponent=ng.getComponent(el);if(!component)return;// Aborts traversal if element is not a componentconstnode: ComponentTreeNode={id: generateId(el),selector: el.tagName.toLowerCase(),tagName: el.tagName.toLowerCase(),children: [],inputs: tryGetInputs(component),};for(constchildofel.querySelectorAll(':scope > *')){walkAngularTree(child,node.children,ng);}out.push(node);}
Reproduction & Failure Scenario
Given an Angular component template with standard HTML wrappers:
walkAngularTree starts at <app-root> and inspects direct child <div class="app-layout">.
ng.getComponent(div) returns null (since <div> is a native DOM element, not a component host).
if (!component) return; fires immediately.
Neither <app-header> nor <app-product-list> are ever reached or added to node.children.
The resulting Component Tree contains only <app-root>.
Proposed Solution
Modify walkAngularTree so that if an element is not a component host, it continues recursing through its child DOM nodes and attaches any discovered child components to the current component node's children array:
functionwalkAngularTree(el: Element,out: ComponentTreeNode[],ng: any){constcomponent=ng.getComponent(el);if(component){constnode: ComponentTreeNode={id: generateId(el),selector: el.tagName.toLowerCase(),tagName: el.tagName.toLowerCase(),children: [],inputs: tryGetInputs(component),};for(constchildofel.children){walkAngularTree(child,node.children,ng);}out.push(node);}else{// Continue traversing through non-component DOM wrapper nodesfor(constchildofel.children){walkAngularTree(child,out,ng);}}}
Hi @santoshyadavdev, while testing the live Component Tree on a sample app with nested layouts, I noticed that child components inside wrapper tags (<div>, <section>, etc.) were not showing up in the tree. Traced it back to walkAngularTree() early-returning on non-component DOM elements.
I have identified the root cause and would love to submit a PR!
Activity
Kaap10 commentedon Sep 23, 2026
Hi @santoshyadavdev, while testing the live Component Tree on a sample app with nested layouts, I noticed that child components inside wrapper tags (
<div>,<section>, etc.) were not showing up in the tree. Traced it back towalkAngularTree()early-returning on non-component DOM elements.I have identified the root cause and would love to submit a PR!
santoshyadavdev commentedon Sep 23, 2026
Go for it, we need as many hands as possible, let's do it 💙
Kaap10 commentedon Sep 24, 2026
Submitted the fix and unit tests in PR #12, ready for review! @santoshyadavdev @erkamyaman
fix(overlay): traverse non-component wrapper elements in `walkAngular…