Skip to content

Commit

Permalink
fix(material/bottom-sheet): changed after checked error with zoneless (
Browse files Browse the repository at this point in the history
…#29277)

Fixes that when closing and immediately reopening bottom sheet in a zoneless app, we were causing a "changed after checked" error to be thrown. It seems to be because we were calling `detectChanges` without marking for check first.

Fixes #29258.

(cherry picked from commit aaea0e2)
  • Loading branch information
crisbeto committed Jun 18, 2024
1 parent 6310016 commit 69ae404
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/material/bottom-sheet/bottom-sheet-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ export class MatBottomSheetContainer extends CdkDialogContainer implements OnDes
this._breakpointSubscription = breakpointObserver
.observe([Breakpoints.Medium, Breakpoints.Large, Breakpoints.XLarge])
.subscribe(() => {
this._toggleClass(
const classList = (this._elementRef.nativeElement as HTMLElement).classList;

classList.toggle(
'mat-bottom-sheet-container-medium',
breakpointObserver.isMatched(Breakpoints.Medium),
);
this._toggleClass(
classList.toggle(
'mat-bottom-sheet-container-large',
breakpointObserver.isMatched(Breakpoints.Large),
);
this._toggleClass(
classList.toggle(
'mat-bottom-sheet-container-xlarge',
breakpointObserver.isMatched(Breakpoints.XLarge),
);
Expand All @@ -111,6 +113,7 @@ export class MatBottomSheetContainer extends CdkDialogContainer implements OnDes
enter(): void {
if (!this._destroyed) {
this._animationState = 'visible';
this._changeDetectorRef.markForCheck();
this._changeDetectorRef.detectChanges();
}
}
Expand Down Expand Up @@ -142,8 +145,4 @@ export class MatBottomSheetContainer extends CdkDialogContainer implements OnDes
}

protected override _captureInitialFocus(): void {}

private _toggleClass(cssClass: string, add: boolean) {
this._elementRef.nativeElement.classList.toggle(cssClass, add);
}
}

0 comments on commit 69ae404

Please sign in to comment.