fix(ivy): error when calling remove() or detach() on an empty view container (#29986)
Fixes Ivy throwing an error if `remove()` or `detach()` are called on an empty `ViewContainerRef`. This PR resolves FW-1270. PR Close #29986
This commit is contained in:

committed by
Ben Lesh

parent
2271f200d7
commit
6ae0084255
@ -371,23 +371,25 @@ export function insertView(lView: LView, lContainer: LContainer, index: number)
|
||||
* @param removeIndex The index of the view to detach
|
||||
* @returns Detached LView instance.
|
||||
*/
|
||||
export function detachView(lContainer: LContainer, removeIndex: number): LView {
|
||||
export function detachView(lContainer: LContainer, removeIndex: number): LView|undefined {
|
||||
const views = lContainer[VIEWS];
|
||||
const viewToDetach = views[removeIndex];
|
||||
if (removeIndex > 0) {
|
||||
views[removeIndex - 1][NEXT] = viewToDetach[NEXT] as LView;
|
||||
}
|
||||
views.splice(removeIndex, 1);
|
||||
addRemoveViewFromContainer(viewToDetach, false);
|
||||
if (viewToDetach) {
|
||||
if (removeIndex > 0) {
|
||||
views[removeIndex - 1][NEXT] = viewToDetach[NEXT] as LView;
|
||||
}
|
||||
views.splice(removeIndex, 1);
|
||||
addRemoveViewFromContainer(viewToDetach, false);
|
||||
|
||||
if ((viewToDetach[FLAGS] & LViewFlags.Attached) &&
|
||||
!(viewToDetach[FLAGS] & LViewFlags.Destroyed) && viewToDetach[QUERIES]) {
|
||||
viewToDetach[QUERIES] !.removeView();
|
||||
if ((viewToDetach[FLAGS] & LViewFlags.Attached) &&
|
||||
!(viewToDetach[FLAGS] & LViewFlags.Destroyed) && viewToDetach[QUERIES]) {
|
||||
viewToDetach[QUERIES] !.removeView();
|
||||
}
|
||||
viewToDetach[PARENT] = null;
|
||||
viewToDetach[NEXT] = null;
|
||||
// Unsets the attached flag
|
||||
viewToDetach[FLAGS] &= ~LViewFlags.Attached;
|
||||
}
|
||||
viewToDetach[PARENT] = null;
|
||||
viewToDetach[NEXT] = null;
|
||||
// Unsets the attached flag
|
||||
viewToDetach[FLAGS] &= ~LViewFlags.Attached;
|
||||
return viewToDetach;
|
||||
}
|
||||
|
||||
@ -399,8 +401,10 @@ export function detachView(lContainer: LContainer, removeIndex: number): LView {
|
||||
*/
|
||||
export function removeView(lContainer: LContainer, removeIndex: number) {
|
||||
const view = lContainer[VIEWS][removeIndex];
|
||||
detachView(lContainer, removeIndex);
|
||||
destroyLView(view);
|
||||
if (view) {
|
||||
detachView(lContainer, removeIndex);
|
||||
destroyLView(view);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user