diff --git a/packages/core/ui/core/view/view-common.ts b/packages/core/ui/core/view/view-common.ts index dec6051669..65ab18f466 100644 --- a/packages/core/ui/core/view/view-common.ts +++ b/packages/core/ui/core/view/view-common.ts @@ -447,7 +447,10 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { this._closeModalCallback = (...originalArgs) => { const cleanupModalViews = () => { const modalIndex = _rootModalViews.indexOf(this); - _rootModalViews.splice(modalIndex, 1); + if (modalIndex > -1) { + _rootModalViews.splice(modalIndex, 1); + } + this._modalParent = null; this._modalContext = null; this._closeModalCallback = null; diff --git a/packages/core/ui/layouts/layout-base-common.ts b/packages/core/ui/layouts/layout-base-common.ts index 95e10c70ff..5e760d2d9e 100644 --- a/packages/core/ui/layouts/layout-base-common.ts +++ b/packages/core/ui/layouts/layout-base-common.ts @@ -50,6 +50,10 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi } public insertChild(child: View, atIndex: number): void { + if (atIndex < 0) { + throw new Error('Cannot insert a child to a negative index.'); + } + this._subViews.splice(atIndex, 0, child); this._addView(child, atIndex); this._registerLayoutChild(child); @@ -60,8 +64,10 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi // TODO: consider caching the index on the child. const index = this._subViews.indexOf(child); - this._subViews.splice(index, 1); - this._unregisterLayoutChild(child); + if (index > -1) { + this._subViews.splice(index, 1); + this._unregisterLayoutChild(child); + } } public removeChildren(): void { diff --git a/packages/core/ui/layouts/root-layout/root-layout-common.ts b/packages/core/ui/layouts/root-layout/root-layout-common.ts index 80dcea5e12..07c239c643 100644 --- a/packages/core/ui/layouts/root-layout/root-layout-common.ts +++ b/packages/core/ui/layouts/root-layout/root-layout-common.ts @@ -93,10 +93,10 @@ export class RootLayoutBase extends GridLayout { }, (err) => { rej(new Error(`Error playing enter animation: ${err}`)); - } + }, ); }); - }) + }), ); Promise.all(toOpen).then( @@ -105,7 +105,7 @@ export class RootLayoutBase extends GridLayout { }, (err) => { reject(err); - } + }, ); }); } @@ -140,7 +140,9 @@ export class RootLayoutBase extends GridLayout { const exitAnimationDefinition = exitTo || poppedView?.options?.animation?.exitTo; // Remove view from tracked popupviews - this.popupViews.splice(popupIndex, 1); + if (popupIndex > -1) { + this.popupViews.splice(popupIndex, 1); + } toClose.push( new Promise((res, rej) => { @@ -153,7 +155,7 @@ export class RootLayoutBase extends GridLayout { } else { res(); } - }) + }), ); if (this.shadeCover) { @@ -177,7 +179,7 @@ export class RootLayoutBase extends GridLayout { }, (err) => { reject(err); - } + }, ); }); } @@ -264,8 +266,8 @@ export class RootLayoutBase extends GridLayout { } // keep the popupViews array in sync with the stacking of the views - const currentView = this.popupViews[this.getPopupIndex(view)]; - this.popupViews.splice(this.getPopupIndex(view), 1); + const currentView = this.popupViews[popupIndex]; + this.popupViews.splice(popupIndex, 1); this.popupViews.push(currentView); const exitAnimation = this.getViewExitState(view);