Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): don't log doctype warning when rendering server-side #6833

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/lib/core/common-behaviors/common-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import {NgModule, InjectionToken, Optional, Inject, isDevMode} from '@angular/core';
import {DOCUMENT} from '@angular/platform-browser';
import {BidiModule} from '@angular/cdk/bidi';
import {CompatibilityModule} from '../compatibility/compatibility';

Expand All @@ -33,19 +32,19 @@ export class MdCommonModule {
/** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */
private _hasDoneGlobalChecks = false;

constructor(
@Optional() @Inject(DOCUMENT) private _document: any,
@Optional() @Inject(MATERIAL_SANITY_CHECKS) _sanityChecksEnabled: boolean) {
/** Reference to the global `document` object. */
private _document = typeof document === 'object' && document ? document : null;

if (_sanityChecksEnabled && !this._hasDoneGlobalChecks && _document && isDevMode()) {
constructor(@Optional() @Inject(MATERIAL_SANITY_CHECKS) sanityChecksEnabled: boolean) {
if (sanityChecksEnabled && !this._hasDoneGlobalChecks && isDevMode()) {
this._checkDoctype();
this._checkTheme();
this._hasDoneGlobalChecks = true;
}
}

private _checkDoctype(): void {
if (!this._document.doctype) {
if (this._document && !this._document.doctype) {
console.warn(
'Current document does not have a doctype. This may cause ' +
'some Angular Material components not to behave as expected.'
Expand All @@ -54,7 +53,7 @@ export class MdCommonModule {
}

private _checkTheme(): void {
if (typeof getComputedStyle === 'function') {
if (this._document && typeof getComputedStyle === 'function') {
const testElement = this._document.createElement('div');

testElement.classList.add('mat-theme-loaded-marker');
Expand Down