Skip to content

Commit 372a443

Browse files
committed
fix: stop unlinking parents on array-valued bindings
setPropertyInternal cleared `parent` and `parentNode` on every array it assigned, working around `_addView` throwing "View already has a parent" when a shared SegmentedBarItem[] was re-bound to a freshly created host inside a ListView item template (NativeScript/nativescript-angular#900). The workaround was both too broad and unsound. It ran for every array-valued binding, so plain data models carrying `parent`/`parentNode` fields were silently mutated, and it threw a TypeError on null or undefined array entries. It also assigned `parent` directly instead of going through `_removeView`, so `_tearDownUI` and `_parentChanged` never ran and `_context` stayed set -- making the new host's `_setupUI` take its `this._context === context` early return and leaving the re-parented view out of the native visual tree entirely. The detach belongs in core, where SegmentedBarBase.onItemsChanged and TabViewBase.onItemsChanged can un-parent through `_removeView` before adopting. This requires that core-side fix to be present.
1 parent 6daed00 commit 372a443

1 file changed

Lines changed: 0 additions & 17 deletions

File tree

packages/angular/src/lib/view-util.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,6 @@ export class ViewUtil {
490490
const propMap = this.getProperties(view);
491491
const propertyName = propMap.get(attributeName);
492492

493-
// Ensure the children of a collection currently have no parent set.
494-
if (Array.isArray(value)) {
495-
this.removeParentReferencesFromItems(value);
496-
}
497-
498493
if (propertyName) {
499494
// We have a lower-upper case mapped property.
500495
view[propertyName] = value;
@@ -505,18 +500,6 @@ export class ViewUtil {
505500
view[attributeName] = value;
506501
}
507502

508-
private removeParentReferencesFromItems(items: any[]): void {
509-
for (const item of items) {
510-
if (item.parent && item.parentNode) {
511-
if (NativeScriptDebug.isLogEnabled()) {
512-
NativeScriptDebug.viewUtilLog(`Unassigning parent ${item.parentNode} on value: ${item}`);
513-
}
514-
item.parent = undefined;
515-
item.parentNode = undefined;
516-
}
517-
}
518-
}
519-
520503
private getProperties(instance: any): Map<string, string> {
521504
const type = instance && instance.constructor;
522505
if (!type) {

0 commit comments

Comments
 (0)