fix(ivy): attempting to remove detached view on destroy (#27585)
Currently the `ViewRef.destroy` method assumes that its index inside the view container will always be valid, however if it has been removed already, it'll be -1 which will throw an error. The error manifested itself in one of the unit tests where a view had been detached during the test and then `TestBed` attempted to destroy its `ComponentRef` which ended threw an `Error during cleanup of component`. PR Close #27585
This commit is contained in:

committed by
Miško Hevery

parent
d32939d51a
commit
5d34657198
@ -60,8 +60,13 @@ export class ViewRef<T> implements viewEngine_EmbeddedViewRef<T>, viewEngine_Int
|
||||
destroy(): void {
|
||||
if (this._appRef) {
|
||||
this._appRef.detachView(this);
|
||||
} else if (this._viewContainerRef && viewAttached(this._lView)) {
|
||||
this._viewContainerRef.detach(this._viewContainerRef.indexOf(this));
|
||||
} else if (this._viewContainerRef) {
|
||||
const index = this._viewContainerRef.indexOf(this);
|
||||
|
||||
if (index > -1) {
|
||||
this._viewContainerRef.detach(index);
|
||||
}
|
||||
|
||||
this._viewContainerRef = null;
|
||||
}
|
||||
destroyLView(this._lView);
|
||||
|
Reference in New Issue
Block a user