From ef78538a065a45660aa7c2de9f5ba8be594e12f9 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 4 Jan 2018 05:59:34 -0800 Subject: [PATCH] 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 --- aio/src/app/shared/attribute-utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aio/src/app/shared/attribute-utils.ts b/aio/src/app/shared/attribute-utils.ts index fa16c2547f..2eb08baa29 100644 --- a/aio/src/app/shared/attribute-utils.ts +++ b/aio/src/app/shared/attribute-utils.ts @@ -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; }