Skip to content

Commit 1f951c8

Browse files
committed
feat(devtools): Modify buildDirectiveForest to set default values for properties that will not be included in the forest returned by non-Angular frameworks.
Set default values for the `directives`, `element`, `hydration`, and `component.isElement` properties of every `ComponentTreeNode` returned by `ng.getComponentForest` for non-Angular apps.
1 parent 87b7ac7 commit 1f951c8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

devtools/projects/ng-devtools-backend/src/lib/component-tree/component-tree.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,19 @@ function discoverNonApplicationRootComponents(element: Element, roots: Set<Eleme
686686
export const buildDirectiveForest = (): ComponentTreeNode[] => {
687687
const ng = ngDebugClient();
688688
if ((ng as any).getComponentForest) {
689-
return (ng as any).getComponentForest();
689+
const forest: ComponentTreeNode[] = (ng as any).getComponentForest();
690+
const frontier = [...forest];
691+
while (frontier.length) {
692+
const node = frontier.pop()!;
693+
node.directives = [];
694+
node.element = node.nativeElement?.nodeName.toLowerCase() ?? '';
695+
node.hydration = null;
696+
node.component!.isElement = false;
697+
for (const child of node.children) {
698+
frontier.push(child);
699+
}
700+
}
701+
return forest;
690702
}
691703
return buildDirectiveForestWithStrategy(getRootElements());
692704
};

0 commit comments

Comments
 (0)