Skip to content

Commit

Permalink
fix(material-experimental): better server-side rendering support for …
Browse files Browse the repository at this point in the history
…progress bar (#19036)

I got some changes in with material-components/material-components-web#5792 which allow us to properly render a progress bar during server-side rendering, instead of turning it into a noop. These changes remove all of the `isBrowser` checks.

I also removed the `isBrowser` check from the MDC checkbox, because the `offsetWidth` access is safe, even though the property might be undefined.
  • Loading branch information
crisbeto committed Apr 17, 2020
1 parent f6be153 commit 5d25d1b
Show file tree
Hide file tree
Showing 6 changed files with 530 additions and 536 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -58,7 +58,7 @@
"@types/youtube": "^0.0.38",
"@webcomponents/custom-elements": "^1.1.0",
"core-js": "^2.6.9",
"material-components-web": "6.0.0-canary.9930d9cc5.0",
"material-components-web": "6.0.0-canary.927fa902c.0",
"rxjs": "^6.5.3",
"systemjs": "0.19.43",
"tslib": "^1.10.0",
Expand Down
1 change: 0 additions & 1 deletion src/material-experimental/mdc-checkbox/BUILD.bazel
Expand Up @@ -23,7 +23,6 @@ ng_module(
module_name = "@angular/material-experimental/mdc-checkbox",
deps = [
"//src/cdk/coercion",
"//src/cdk/platform",
"//src/material/checkbox",
"//src/material/core",
"@npm//@angular/animations",
Expand Down
4 changes: 1 addition & 3 deletions src/material-experimental/mdc-checkbox/checkbox.ts
Expand Up @@ -7,7 +7,6 @@
*/

import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
import {Platform} from '@angular/cdk/platform';
import {
AfterViewInit,
Attribute,
Expand Down Expand Up @@ -211,7 +210,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
private _checkboxAdapter: MDCCheckboxAdapter = {
addClass: (className) => this._setClass(className, true),
removeClass: (className) => this._setClass(className, false),
forceLayout: () => this._platform.isBrowser && this._checkbox.nativeElement.offsetWidth,
forceLayout: () => this._checkbox.nativeElement.offsetWidth,
hasNativeControl: () => !!this._nativeCheckbox,
isAttachedToDOM: () => !!this._checkbox.nativeElement.parentNode,
isChecked: () => this.checked,
Expand All @@ -233,7 +232,6 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess

constructor(
private _changeDetectorRef: ChangeDetectorRef,
private _platform: Platform,
@Attribute('tabindex') tabIndex: string,
/**
* @deprecated `_clickAction` parameter to be removed, use
Expand Down
1 change: 0 additions & 1 deletion src/material-experimental/mdc-progress-bar/BUILD.bazel
Expand Up @@ -23,7 +23,6 @@ ng_module(
module_name = "@angular/material-experimental/mdc-progress-bar",
deps = [
"//src/cdk/bidi",
"//src/cdk/platform",
"//src/material/core",
"//src/material/progress-bar",
"@npm//@angular/core",
Expand Down
7 changes: 2 additions & 5 deletions src/material-experimental/mdc-progress-bar/progress-bar.ts
Expand Up @@ -27,7 +27,6 @@ import {MDCLinearProgressAdapter, MDCLinearProgressFoundation} from '@material/l
import {Subscription, fromEvent, Observable} from 'rxjs';
import {filter} from 'rxjs/operators';
import {Directionality} from '@angular/cdk/bidi';
import {Platform} from '@angular/cdk/platform';

// Boilerplate for applying mixins to MatProgressBar.
/** @docs-private */
Expand Down Expand Up @@ -63,7 +62,6 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie

constructor(public _elementRef: ElementRef<HTMLElement>,
private _ngZone: NgZone,
private _platform: Platform,
@Optional() private _dir?: Directionality,
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
super(_elementRef);
Expand All @@ -79,7 +77,7 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
/** Adapter used by MDC to interact with the DOM. */
private _adapter: MDCLinearProgressAdapter = {
addClass: (className: string) => this._rootElement.classList.add(className),
forceLayout: () => this._platform.isBrowser && this._rootElement.offsetWidth,
forceLayout: () => this._rootElement.offsetWidth,
removeAttribute: (name: string) => this._rootElement.removeAttribute(name),
setAttribute: (name: string, value: string) => this._rootElement.setAttribute(name, value),
hasClass: (className: string) => this._rootElement.classList.contains(className),
Expand Down Expand Up @@ -184,8 +182,7 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
private _syncFoundation() {
const foundation = this._foundation;

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

Expand Down

0 comments on commit 5d25d1b

Please sign in to comment.