@@ -93,6 +93,7 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
9393 'class' : 'mat-drawer-content' ,
9494 '[style.margin-left.px]' : '_container._contentMargins.left' ,
9595 '[style.margin-right.px]' : '_container._contentMargins.right' ,
96+ '[class.mat-drawer-content-hidden]' : '_shouldBeHidden()' ,
9697 } ,
9798 changeDetection : ChangeDetectionStrategy . OnPush ,
9899 encapsulation : ViewEncapsulation . None ,
@@ -104,6 +105,7 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
104105 ] ,
105106} )
106107export class MatDrawerContent extends CdkScrollable implements AfterContentInit {
108+ private _platform = inject ( Platform ) ;
107109 private _changeDetectorRef = inject ( ChangeDetectorRef ) ;
108110 _container = inject ( MatDrawerContainer ) ;
109111
@@ -122,6 +124,24 @@ export class MatDrawerContent extends CdkScrollable implements AfterContentInit
122124 this . _changeDetectorRef . markForCheck ( ) ;
123125 } ) ;
124126 }
127+
128+ /** Determines whether the content element should be hidden from the user. */
129+ protected _shouldBeHidden ( ) : boolean {
130+ // In some modes the content is pushed based on the width of the opened sidenavs, however on
131+ // the server we can't measure the sidenav so the margin is always zero. This can cause the
132+ // content to jump around when it's rendered on the server and hydrated on the client. We
133+ // avoid it by hiding the content on the initial render and then showing it once the sidenav
134+ // has been measured on the client.
135+ if ( this . _platform . isBrowser ) {
136+ return false ;
137+ }
138+
139+ const { start, end} = this . _container ;
140+ return (
141+ ( start != null && start . mode !== 'over' && start . opened ) ||
142+ ( end != null && end . mode !== 'over' && end . opened )
143+ ) ;
144+ }
125145}
126146
127147/**
0 commit comments