-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(menu,toolbar): avoid potential server-side rendering errors #9423
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,12 @@ import { | |
ElementRef, | ||
isDevMode, | ||
QueryList, | ||
ViewEncapsulation | ||
ViewEncapsulation, | ||
Inject, | ||
} from '@angular/core'; | ||
import {CanColor, mixinColor} from '@angular/material/core'; | ||
import {Platform} from '@angular/cdk/platform'; | ||
import {DOCUMENT} from '@angular/common'; | ||
|
||
// Boilerplate for applying mixins to MatToolbar. | ||
/** @docs-private */ | ||
|
@@ -51,12 +53,19 @@ export class MatToolbarRow {} | |
preserveWhitespaces: false, | ||
}) | ||
export class MatToolbar extends _MatToolbarMixinBase implements CanColor, AfterViewInit { | ||
private _document: Document; | ||
|
||
/** Reference to all toolbar row elements that have been projected. */ | ||
@ContentChildren(MatToolbarRow) _toolbarRows: QueryList<MatToolbarRow>; | ||
|
||
constructor(elementRef: ElementRef, private _platform: Platform) { | ||
constructor( | ||
elementRef: ElementRef, | ||
private _platform: Platform, | ||
@Inject(DOCUMENT) document?: any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @crisbeto I know this PR has already been merged, but shouldn't this have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we had the tooling around |
||
super(elementRef); | ||
|
||
// TODO: make the document a required param when doing breaking changes. | ||
this._document = document; | ||
} | ||
|
||
ngAfterViewInit() { | ||
|
@@ -80,7 +89,7 @@ export class MatToolbar extends _MatToolbarMixinBase implements CanColor, AfterV | |
// a <mat-toolbar-row> element. | ||
const isCombinedUsage = [].slice.call(this._elementRef.nativeElement.childNodes) | ||
.filter(node => !(node.classList && node.classList.contains('mat-toolbar-row'))) | ||
.filter(node => node.nodeType !== Node.COMMENT_NODE) | ||
.filter(node => node.nodeType !== (this._document ? this._document.COMMENT_NODE : 8)) | ||
.some(node => node.textContent.trim()); | ||
|
||
if (isCombinedUsage) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make constants for node types until
_document
is always available?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined not to, because we'll end up sprinkling them everywhere and it'll make it more likely to forget about removing them.