Skip to content

Commit 330176d

Browse files
crisbetojelbourn
authored andcommitted
fix(sidenav): continuously hitting zone when using autosize option (#12067)
Fixes the sidenav going into an infinite change detection loop when using the `autosize` option. Initially this was fixed in #11231, but it got reintroduced in #11986 where we started comparing `0` against `null` which always evaluates to true. Fixes #11215.
1 parent cc5dfb8 commit 330176d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/lib/sidenav/drawer.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,15 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
702702
}
703703
}
704704

705+
// If either `right` or `left` is zero, don't set a style to the element. This
706+
// allows users to specify a custom size via CSS class in SSR scenarios where the
707+
// measured widths will always be zero. Note that we reset to `null` here, rather
708+
// than below, in order to ensure that the types in the `if` below are consistent.
709+
left = left || null!;
710+
right = right || null!;
711+
705712
if (left !== this._contentMargins.left || right !== this._contentMargins.right) {
706-
this._contentMargins = {
707-
// If either `right` or `left` is zero, don't set a style to the element. This
708-
// allows users to specify a custom size via CSS class in SSR scenarios where the
709-
// measured widths will always be zero.
710-
left: left || null,
711-
right: right || null,
712-
};
713+
this._contentMargins = {left, right};
713714

714715
// Pull back into the NgZone since in some cases we could be outside. We need to be careful
715716
// to do it only when something changed, otherwise we can end up hitting the zone too often.

0 commit comments

Comments
 (0)