Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(table): Fixes an issue with a ViewContainer error on destroy.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomheller authored and ffriedl89 committed Dec 2, 2020
1 parent b5f4e80 commit 36728ee
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion libs/barista-components/table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,33 @@ export class DtTable<T> extends _DtTableBase<T> implements OnDestroy {
* through an Observable stream (directly or from a DataSource).
*/
renderRows(): void {
super.renderRows();
// To prevent an error that was thrown when the the component containing
// the table was destroyed. `"Cannot move a destroyed View in a ViewContainer!"`
//
// This check is necessary because the cdkTable does not check
// if the view is already destroyed before moving it
// https://github.com/angular/components/blob/c68791db9a0b4107d04fa924c27a087cd00a8989/src/cdk/table/table.ts#L637
//
// The dependency for the _rowOutlet internal is safe, as we already
// depend on this one for the template as well.
const rowOutletViewContainer = this._rowOutlet.viewContainer;
let shouldRender = false;

// Figure out if all views within the viewContainer are already
// destroyed.
for (let i = 0; i < rowOutletViewContainer.length; i += 1) {
const view = rowOutletViewContainer.get(i);
if (view!.destroyed === false) {
shouldRender = true;
break;
}
}

// Only if not all view containers have been destroyed, or if
// there are no viewContainers at all.
if (shouldRender || rowOutletViewContainer.length === 0) {
super.renderRows();
}

// no need if there is no empty state provided via content projection
if (!this._emptyState.first) {
Expand Down

0 comments on commit 36728ee

Please sign in to comment.