Skip to content

Commit

Permalink
fix: delay on-load sanity checks
Browse files Browse the repository at this point in the history
Delays the sanity checks from the `CompatibilityModule` by 5 seconds, in order to give the user's base styles a better chance to load.

Fixes #4125.
  • Loading branch information
crisbeto committed Apr 21, 2017
1 parent 8d0cd04 commit 4c850c7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/lib/core/compatibility/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Optional,
isDevMode,
ElementRef,
NgZone,
} from '@angular/core';
import {DOCUMENT} from '@angular/platform-browser';
import {MdError} from '../errors/error';
Expand Down Expand Up @@ -193,16 +194,21 @@ export class CompatibilityModule {
};
}

constructor(@Optional() @Inject(DOCUMENT) private _document: any) {
if (!hasDoneGlobalChecks && isDevMode()) {
this._checkDoctype();
this._checkTheme();
hasDoneGlobalChecks = true;
constructor(@Optional() @Inject(DOCUMENT) private _document: any, ngZone: NgZone) {
if (!hasDoneGlobalChecks && _document && isDevMode()) {
ngZone.runOutsideAngular(() => {
// Delay running the check to allow more time for the user's styles to load.
setTimeout(() => {
this._checkDoctype();
this._checkTheme();
hasDoneGlobalChecks = true;
}, 5000);
});
}
}

private _checkDoctype(): void {
if (this._document && !this._document.doctype) {
if (!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 @@ -211,7 +217,7 @@ export class CompatibilityModule {
}

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

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

0 comments on commit 4c850c7

Please sign in to comment.