Skip to content

Commit c134026

Browse files
crisbetojelbourn
authored andcommitted
fix: sanity checks throwing an error if scripts are set in the head (#12068)
Fixes the sanity checks throwing an error if they run too early and they're inserted before the `body`. Fixes #12026.
1 parent 5c6f25e commit c134026

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ export class MatCommonModule {
7272
}
7373

7474
private _checkThemeIsPresent(): void {
75-
if (this._document && typeof getComputedStyle === 'function') {
75+
// We need to assert that the `body` is defined, because these checks run very early
76+
// and the `body` won't be defined if the consumer put their scripts in the `head`.
77+
if (this._document && this._document.body && typeof getComputedStyle === 'function') {
7678
const testElement = this._document.createElement('div');
7779

7880
testElement.classList.add('mat-theme-loaded-marker');
7981
this._document.body.appendChild(testElement);
8082

8183
const computedStyle = getComputedStyle(testElement);
8284

83-
// In some situations, the computed style of the test element can be null. For example in
85+
// In some situations the computed style of the test element can be null. For example in
8486
// Firefox, the computed style is null if an application is running inside of a hidden iframe.
8587
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397
8688
if (computedStyle && computedStyle.display !== 'none') {

0 commit comments

Comments
 (0)