From f805d6c8a7c0cfea690fb419ff7584c5bfc4a26a Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 18 Apr 2018 17:07:30 +0200 Subject: [PATCH 1/3] fixed updating namespaced attributes is broken --- lib/morph.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/morph.js b/lib/morph.js index ccc20cf..82e6f11 100644 --- a/lib/morph.js +++ b/lib/morph.js @@ -47,8 +47,15 @@ function copyAttrs (newNode, oldNode) { attrNamespaceURI = attr.namespaceURI attrValue = attr.value if (attrNamespaceURI) { - attrName = attr.localName || attrName - fromValue = oldNode.getAttributeNS(attrNamespaceURI, attrName) + var attrLocalName = attr.localName + + // Important: getAttributeNS expects the localName of a namespaced attribute + // but setAttributeNS requires the fully qualified name + // ref: https://dom.spec.whatwg.org/#dom-element-getattributens + // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-localname + // ref: https://dom.spec.whatwg.org/#dom-element-setattributens + // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-qualifiedname + fromValue = oldNode.getAttributeNS(attrNamespaceURI, attrLocalName) if (fromValue !== attrValue) { oldNode.setAttributeNS(attrNamespaceURI, attrName, attrValue) } From 6a93c320e83c8b1541eee2ea145113bec0a1a9d2 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Fri, 20 Apr 2018 19:58:31 +0200 Subject: [PATCH 2/3] just in case localName is not available --- lib/morph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/morph.js b/lib/morph.js index 82e6f11..beb735d 100644 --- a/lib/morph.js +++ b/lib/morph.js @@ -55,7 +55,7 @@ function copyAttrs (newNode, oldNode) { // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-localname // ref: https://dom.spec.whatwg.org/#dom-element-setattributens // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-qualifiedname - fromValue = oldNode.getAttributeNS(attrNamespaceURI, attrLocalName) + fromValue = oldNode.getAttributeNS(attrNamespaceURI, attrLocalName || attrName) if (fromValue !== attrValue) { oldNode.setAttributeNS(attrNamespaceURI, attrName, attrValue) } From cb0884fb5736b3ba0254bf72c497a7e85dd2608e Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Fri, 20 Apr 2018 21:55:44 +0200 Subject: [PATCH 3/3] movend comments to related api call --- lib/morph.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/morph.js b/lib/morph.js index beb735d..f32eb48 100644 --- a/lib/morph.js +++ b/lib/morph.js @@ -50,13 +50,13 @@ function copyAttrs (newNode, oldNode) { var attrLocalName = attr.localName // Important: getAttributeNS expects the localName of a namespaced attribute - // but setAttributeNS requires the fully qualified name // ref: https://dom.spec.whatwg.org/#dom-element-getattributens // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-localname - // ref: https://dom.spec.whatwg.org/#dom-element-setattributens - // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-qualifiedname fromValue = oldNode.getAttributeNS(attrNamespaceURI, attrLocalName || attrName) if (fromValue !== attrValue) { + // but setAttributeNS requires the fully qualified name + // ref: https://dom.spec.whatwg.org/#dom-element-setattributens + // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-qualifiedname oldNode.setAttributeNS(attrNamespaceURI, attrName, attrValue) } } else {