Skip to content

Commit c0ea5c6

Browse files
committed
fix: PrimeNG p-tree refresh on node expand
Replace refreshTrigger.update() with _rootOptionsData.update(prev => [...prev]) in handleOptionsResponse for both connect and download components. PrimeNG p-tree does reference-equality check on [value] binding. The old approach mutated node.children in-place and incremented a trigger signal, but rootOptions computed still returned the same array reference — PrimeNG never detected the change. Spreading into a new array fixes this. Remove unused refreshTrigger from connect.component.ts. In download it remains for file-action toggle (unrelated to p-tree).
1 parent a51f720 commit c0ea5c6

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

src/app/connect/connect.component.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,8 @@ export class ConnectComponent
153153
private readonly _rootOptionsData = signal<TreeNode<string>[]>(
154154
createPlaceholderRootOptions(),
155155
);
156-
// Used to trigger view updates when tree nodes are mutated
157-
readonly refreshTrigger = signal(0);
158-
// Computed signal that tracks refreshTrigger for change detection
159-
readonly rootOptions = computed(() => {
160-
this.refreshTrigger(); // Track refresh trigger to force re-render
161-
return this._rootOptionsData();
162-
});
156+
// Computed signal for template binding
157+
readonly rootOptions = computed(() => this._rootOptionsData());
163158
readonly selectedOption = signal<TreeNode<string> | undefined>(undefined);
164159

165160
// Both accordion panels expanded by default
@@ -1306,8 +1301,8 @@ export class ConnectComponent
13061301
// Expanding an existing node - add children
13071302
const nodes = convertToTreeNodes(items);
13081303
node.children = nodes.treeNodes;
1309-
// Increment refresh trigger to force change detection (zoneless Angular)
1310-
this.refreshTrigger.update((n) => n + 1);
1304+
// Create new array reference so PrimeNG p-tree detects the change
1305+
this._rootOptionsData.update((prev) => [...prev]);
13111306
this.optionsLoading.set(false);
13121307
this.autoSelectNode(nodes.selectedNode);
13131308
} else if (items && items.length > 0) {

src/app/download/download.component.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,8 @@ export class DownloadComponent
154154
private readonly _rootOptionsData = signal<TreeNode<string>[]>(
155155
createPlaceholderRootOptions(),
156156
);
157-
// Computed signal that tracks refreshTrigger for change detection
158-
readonly rootOptions = computed(() => {
159-
this.refreshTrigger(); // Track refresh trigger to force re-render
160-
return this._rootOptionsData();
161-
});
157+
// Computed signal for template binding
158+
readonly rootOptions = computed(() => this._rootOptionsData());
162159
selectedOption = signal<TreeNode<string> | undefined>(undefined);
163160
optionsLoading = signal(false);
164161
globusPlugin = signal<RepoPlugin | undefined>(undefined);
@@ -1094,8 +1091,8 @@ export class DownloadComponent
10941091
// Expanding an existing node - add children
10951092
const nodes = convertToTreeNodes(items);
10961093
node.children = nodes.treeNodes;
1097-
// Increment refresh trigger to force change detection (zoneless Angular)
1098-
this.refreshTrigger.update((n) => n + 1);
1094+
// Create new array reference so PrimeNG p-tree detects the change
1095+
this._rootOptionsData.update((prev) => [...prev]);
10991096
this.optionsLoading.set(false);
11001097
this.autoSelectNode(nodes.selectedNode);
11011098
} else if (items && items.length > 0) {

0 commit comments

Comments
 (0)