Skip to content

Commit 22b0660

Browse files
crisbetojelbourn
authored andcommitted
fix(core): log warning if doctype is missing (#2849)
Logs a warning if the user's document doesn't have a doctype. This has been an issue in the past with some hard-to-track-down bugs which ended up being due to the browser running in quirks mode. Fixes #2351.
1 parent 5c1474d commit 22b0660

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib/core/compatibility/compatibility.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
OpaqueToken,
66
Inject,
77
Optional,
8+
isDevMode,
89
} from '@angular/core';
10+
import {DOCUMENT} from '@angular/platform-browser';
911

1012

1113
export const MATERIAL_COMPATIBILITY_MODE = new OpaqueToken('md-compatibility-mode');
@@ -71,7 +73,7 @@ export const MAT_ELEMENTS_SELECTOR = `
7173
mat-toolbar`;
7274

7375
/** Selector that matches all elements that may have style collisions with AngularJS Material. */
74-
export const MD_ELEMENTS_SELECTOR = `
76+
export const MD_ELEMENTS_SELECTOR = `
7577
[md-button],
7678
[md-dialog-actions],
7779
[md-dialog-close],
@@ -167,6 +169,15 @@ export class CompatibilityModule {
167169
providers: [],
168170
};
169171
}
172+
173+
constructor(@Optional() @Inject(DOCUMENT) document: any) {
174+
if (isDevMode() && typeof document && !document.doctype) {
175+
console.warn(
176+
'Current document does not have a doctype. This may cause ' +
177+
'some Angular Material components not to behave as expected.'
178+
);
179+
}
180+
}
170181
}
171182

172183

0 commit comments

Comments
 (0)