fix(aio): don't use Object.keys on NamedNodeMap to prevent SEO errors (#21305)

Apparently Object.keys on NamedNodeMap work differently with googlebot :-(

There are not tests since we don't have a way to write tests for googlebot,
but I did manually verify that after this fix googlebot correctly renders
several of the previously broken pages.

Fixes #21272

PR Close #21305
This commit is contained in:
Igor Minar 2018-01-04 05:59:34 -08:00 committed by Kara Erickson
parent ccea37256e
commit ef78538a06
1 changed files with 3 additions and 2 deletions

View File

@ -11,8 +11,9 @@ interface StringMap { [index: string]: string; }
export function getAttrs(el: HTMLElement | ElementRef): StringMap {
const attrs: NamedNodeMap = el instanceof ElementRef ? el.nativeElement.attributes : el.attributes;
const attrMap = {};
Object.keys(attrs).forEach(key =>
attrMap[(attrs[key] as Attr).name.toLowerCase()] = (attrs[key] as Attr).value);
for (const attr of attrs as any /* cast due to https://github.com/Microsoft/TypeScript/issues/2695 */) {
attrMap[attr.name.toLowerCase()] = attr.value;
}
return attrMap;
}