Skip to content

Commit

Permalink
fix(common-module): check if computed styles are available (#7003)
Browse files Browse the repository at this point in the history
* fix(common-module): check if computed styles are available

Due to a Firefox Bug (https://bugzilla.mozilla.org/show_bug.cgi?id=548397) the `getComputedStyle` call in the `MdCommonModule` will return `null` and cause a runtime exception because normally the computed styles are never `null` for the test element.

Since this it's very uncommon that a developer places a Angular Material application inside of a hidden iframe, a simple null check should be enough to get the application running.

Fixes #7000

* Add comment about Firefox case
devversion authored and andrewseguin committed Sep 29, 2017
1 parent dcf1074 commit 5da9e64
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/core/common-behaviors/common-module.ts
Original file line number Diff line number Diff line change
@@ -60,7 +60,12 @@ export class MatCommonModule {
testElement.classList.add('mat-theme-loaded-marker');
this._document.body.appendChild(testElement);

if (getComputedStyle(testElement).display !== 'none') {
const computedStyle = getComputedStyle(testElement);

// In some situations, the computed style of the test element can be null. For example in
// Firefox, the computed style is null if an application is running inside of a hidden iframe.
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397
if (computedStyle && computedStyle.display !== 'none') {
console.warn(
'Could not find Angular Material core theme. Most Material ' +
'components may not work as expected. For more info refer ' +

0 comments on commit 5da9e64

Please sign in to comment.