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 angular#4125.
  • Loading branch information
crisbeto committed Apr 20, 2017
1 parent 8d0cd04 commit 3e93425
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 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,11 +194,16 @@ export class CompatibilityModule {
};
}

constructor(@Optional() @Inject(DOCUMENT) private _document: any) {
constructor(@Optional() @Inject(DOCUMENT) private _document: any, ngZone: NgZone) {
if (!hasDoneGlobalChecks && isDevMode()) {
this._checkDoctype();
this._checkTheme();
hasDoneGlobalChecks = true;
ngZone.runOutsideAngular(() => {
// Delay running the check, in case the base page styles haven't been loaded yet.
setTimeout(() => {
this._checkDoctype();
this._checkTheme();
hasDoneGlobalChecks = true;
}, 5000);
});
}
}

Expand Down

0 comments on commit 3e93425

Please sign in to comment.