Skip to content

Commit 1d431a9

Browse files
hawkgsalxhub
authored andcommitted
fix(devtools): router tree not being rendered
Convert the `TreeVisualizer` to a signal, in the `TreeVisualizerComponent`, to ensure that the router tree render effect is always called; Use explicit `afterNextRender` phases.
1 parent 37598cf commit 1d431a9

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

devtools/projects/ng-devtools/src/lib/shared/tree-visualizer/tree-visualizer.component.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,31 @@ export class TreeVisualizerComponent<T extends TreeNode = TreeNode> {
5656
protected readonly nodeMouseover = output<TreeD3Node<T>>();
5757

5858
readonly panning = signal(false);
59+
private readonly visualizer = signal<TreeVisualizer<T> | null>(null);
5960

6061
private initialRender: boolean = true;
61-
private visualizer?: TreeVisualizer<T>;
6262

6363
constructor() {
64-
afterNextRender(() => {
65-
this.visualizer?.cleanup();
66-
this.visualizer = new TreeVisualizer<T>(
67-
this.container().nativeElement,
68-
this.group().nativeElement,
69-
this.config(),
70-
);
71-
this.ready.emit();
64+
afterNextRender({
65+
write: () => this.visualizer()?.cleanup(), // Cleans up the visualization DOM
66+
read: () => {
67+
this.visualizer.set(
68+
new TreeVisualizer<T>(
69+
this.container().nativeElement,
70+
this.group().nativeElement,
71+
this.config(),
72+
),
73+
);
74+
this.ready.emit();
75+
},
7276
});
7377

7478
effect(() => {
7579
this.renderGraph(this.root());
7680
});
7781

7882
inject(DestroyRef).onDestroy(() => {
79-
this.visualizer?.dispose();
83+
this.visualizer()?.dispose();
8084
});
8185
}
8286

@@ -85,26 +89,27 @@ export class TreeVisualizerComponent<T extends TreeNode = TreeNode> {
8589
}
8690

8791
snapToRoot(scale?: number) {
88-
this.visualizer?.snapToRoot(scale);
92+
this.visualizer()?.snapToRoot(scale);
8993
}
9094

9195
snapToNode(node: T, scale?: number) {
92-
this.visualizer?.snapToNode(node, scale);
96+
this.visualizer()?.snapToNode(node, scale);
9397
}
9498

9599
getNodeById(id: string) {
96-
return this.visualizer?.getInternalNodeById(id);
100+
return this.visualizer()?.getInternalNodeById(id);
97101
}
98102

99103
private renderGraph(root: T): void {
100-
if (!this.visualizer) {
104+
const visualizer = this.visualizer();
105+
if (!visualizer) {
101106
return;
102107
}
103108

104-
this.visualizer.render(root);
105-
this.visualizer.onNodeClick((_, node) => this.nodeClick.emit(node));
106-
this.visualizer.onNodeMouseout((_, node) => this.nodeMouseout.emit(node));
107-
this.visualizer.onNodeMouseover((_, node) => this.nodeMouseover.emit(node));
109+
visualizer.render(root);
110+
visualizer.onNodeClick((_, node) => this.nodeClick.emit(node));
111+
visualizer.onNodeMouseout((_, node) => this.nodeMouseout.emit(node));
112+
visualizer.onNodeMouseover((_, node) => this.nodeMouseover.emit(node));
108113

109114
this.render.emit({initial: this.initialRender});
110115
if (this.initialRender) {

0 commit comments

Comments
 (0)