Skip to content

Commit e103a21

Browse files
biggs0125wagnermaciel
authored andcommitted
fix(cdk-experimental/column-resize): Ensure resizable entity is not destroyed before applying min/max update (#24007)
The styleSchedule.scheduleEnd() function will sometimes call the provided callback after the nativeElement has been destroyed. The width of this nativeElement is used in the _apply(Min/Max)WidthPx functions to calculate a width diff. If the nativeElement has already been destroyed, the "current" width of the element is 0 so the column effectively doubles in width even though it technically didn't change. This width change is propagated up to the table which increases its size to account for the increased column width. If the element has been destroyed, we can just ignore any resize logic pertaining to that old column since it should no longer affect the table's width. A newer version of that entity should make the change if necessary. (cherry picked from commit 35cdf7c)
1 parent dddc933 commit e103a21

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/cdk-experimental/column-resize/resizable.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
6767
protected abstract readonly changeDetectorRef: ChangeDetectorRef;
6868

6969
private _viewInitialized = false;
70+
private _isDestroyed = false;
7071

7172
/** The minimum width to allow the column to be sized to. */
7273
get minWidthPx(): number {
@@ -100,13 +101,15 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
100101
this._appendInlineHandle();
101102

102103
this.styleScheduler.scheduleEnd(() => {
104+
if (this._isDestroyed) return;
103105
this._viewInitialized = true;
104106
this._applyMinWidthPx();
105107
this._applyMaxWidthPx();
106108
});
107109
}
108110

109111
ngOnDestroy(): void {
112+
this._isDestroyed = true;
110113
this.destroyed.next();
111114
this.destroyed.complete();
112115
this.inlineHandle?.remove();

0 commit comments

Comments
 (0)