Skip to content

Commit b30aedd

Browse files
crisbetojelbourn
authored andcommitted
fix(material-experimental/progress-bar): server-side rendering error (#17359)
Fixes a server-side rendering error that is thrown from the MDC-based progress bar.
1 parent 9ee6b26 commit b30aedd

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/material-experimental/mdc-progress-bar/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ng_module(
2323
module_name = "@angular/material-experimental/mdc-progress-bar",
2424
deps = [
2525
"//src/cdk/bidi",
26+
"//src/cdk/platform",
2627
"//src/material/core",
2728
"//src/material/progress-bar",
2829
"@npm//@angular/core",

src/material-experimental/mdc-progress-bar/progress-bar.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {MDCLinearProgressAdapter, MDCLinearProgressFoundation} from '@material/l
2727
import {Subscription, fromEvent, Observable} from 'rxjs';
2828
import {filter} from 'rxjs/operators';
2929
import {Directionality} from '@angular/cdk/bidi';
30+
import {Platform} from '@angular/cdk/platform';
3031

3132
// Boilerplate for applying mixins to MatProgressBar.
3233
/** @docs-private */
@@ -63,6 +64,7 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
6364

6465
constructor(public _elementRef: ElementRef<HTMLElement>,
6566
private _ngZone: NgZone,
67+
private _platform: Platform,
6668
@Optional() private _dir?: Directionality,
6769
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
6870
super(_elementRef);
@@ -189,7 +191,8 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
189191
private _syncFoundation() {
190192
const foundation = this._foundation;
191193

192-
if (foundation) {
194+
// Don't sync any state if we're not in a browser, because MDC uses some window APIs.
195+
if (foundation && this._platform.isBrowser) {
193196
const direction = this._dir ? this._dir.value : 'ltr';
194197
const mode = this.mode;
195198

0 commit comments

Comments
 (0)