|
8 | 8 |
|
9 | 9 | import {HighContrastModeDetector} from '@angular/cdk/a11y'; |
10 | 10 | import {BidiModule} from '@angular/cdk/bidi'; |
11 | | -import {Inject, InjectionToken, NgModule, Optional} from '@angular/core'; |
| 11 | +import {inject, Inject, InjectionToken, NgModule, Optional} from '@angular/core'; |
12 | 12 | import {VERSION as CDK_VERSION} from '@angular/cdk'; |
13 | 13 | import {DOCUMENT} from '@angular/common'; |
14 | | -import {_isTestEnvironment} from '@angular/cdk/platform'; |
| 14 | +import {Platform, _isTestEnvironment} from '@angular/cdk/platform'; |
15 | 15 | import {VERSION} from '../version'; |
16 | 16 |
|
17 | 17 | /** @docs-private */ |
@@ -65,12 +65,15 @@ export class MatCommonModule { |
65 | 65 | this._hasDoneGlobalChecks = true; |
66 | 66 |
|
67 | 67 | if (typeof ngDevMode === 'undefined' || ngDevMode) { |
| 68 | + // Inject in here so the reference to `Platform` can be removed in production mode. |
| 69 | + const platform = inject(Platform, {optional: true}); |
| 70 | + |
68 | 71 | if (this._checkIsEnabled('doctype')) { |
69 | 72 | _checkDoctypeIsDefined(this._document); |
70 | 73 | } |
71 | 74 |
|
72 | 75 | if (this._checkIsEnabled('theme')) { |
73 | | - _checkThemeIsPresent(this._document); |
| 76 | + _checkThemeIsPresent(this._document, !!platform?.isBrowser); |
74 | 77 | } |
75 | 78 |
|
76 | 79 | if (this._checkIsEnabled('version')) { |
@@ -105,10 +108,10 @@ function _checkDoctypeIsDefined(doc: Document): void { |
105 | 108 | } |
106 | 109 |
|
107 | 110 | /** Checks that a theme has been included. */ |
108 | | -function _checkThemeIsPresent(doc: Document): void { |
| 111 | +function _checkThemeIsPresent(doc: Document, isBrowser: boolean): void { |
109 | 112 | // We need to assert that the `body` is defined, because these checks run very early |
110 | 113 | // and the `body` won't be defined if the consumer put their scripts in the `head`. |
111 | | - if (!doc.body || typeof getComputedStyle !== 'function') { |
| 114 | + if (!doc.body || !isBrowser) { |
112 | 115 | return; |
113 | 116 | } |
114 | 117 |
|
|
0 commit comments