Skip to content

Commit 5da9e64

Browse files
devversionandrewseguin
authored andcommitted
fix(common-module): check if computed styles are available (#7003)
* 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
1 parent dcf1074 commit 5da9e64

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/lib/core/common-behaviors/common-module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ export class MatCommonModule {
6060
testElement.classList.add('mat-theme-loaded-marker');
6161
this._document.body.appendChild(testElement);
6262

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

0 commit comments

Comments
 (0)