From d5996f466df8361649c4bdaacabd299989aa9720 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 18 Apr 2018 20:48:09 +0200 Subject: [PATCH 1/4] fixed namespaced attributes not updating --- src/morphAttrs.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/morphAttrs.js b/src/morphAttrs.js index 35f76c4..1f961d2 100644 --- a/src/morphAttrs.js +++ b/src/morphAttrs.js @@ -16,11 +16,17 @@ export default function morphAttrs(fromNode, toNode) { attrValue = attr.value; if (attrNamespaceURI) { - attrName = attr.localName || attrName; - fromValue = fromNode.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 = fromNode.getAttributeNS(attrNamespaceURI, attrLocalName) if (fromValue !== attrValue) { - fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); + fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue) } } else { fromValue = fromNode.getAttribute(attrName); From 915b90cf48f149324b9436c2235c4390937d4861 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 18 Apr 2018 20:54:59 +0200 Subject: [PATCH 2/4] fixed missing semis --- src/morphAttrs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/morphAttrs.js b/src/morphAttrs.js index 1f961d2..14d4a3f 100644 --- a/src/morphAttrs.js +++ b/src/morphAttrs.js @@ -16,7 +16,7 @@ export default function morphAttrs(fromNode, toNode) { attrValue = attr.value; if (attrNamespaceURI) { - var attrLocalName = attr.localName + var attrLocalName = attr.localName; // Important: getAttributeNS expects the localName of a namespaced attribute // but setAttributeNS requires the fully qualified name @@ -24,9 +24,9 @@ export default function morphAttrs(fromNode, toNode) { // 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 = fromNode.getAttributeNS(attrNamespaceURI, attrLocalName) + fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrLocalName); if (fromValue !== attrValue) { - fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue) + fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); } } else { fromValue = fromNode.getAttribute(attrName); From a26daa3dc6e631e582dec9f3d9e644c0e99a8fd2 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Fri, 20 Apr 2018 19:57:33 +0200 Subject: [PATCH 3/4] just in case local name is not available --- src/morphAttrs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/morphAttrs.js b/src/morphAttrs.js index 14d4a3f..de58214 100644 --- a/src/morphAttrs.js +++ b/src/morphAttrs.js @@ -24,7 +24,7 @@ export default function morphAttrs(fromNode, toNode) { // 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 = fromNode.getAttributeNS(attrNamespaceURI, attrLocalName); + fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrLocalName || attrName); if (fromValue !== attrValue) { fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); } From 3c8e5faaf8e2b22eec8382d2aedfbae33a30b038 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Fri, 20 Apr 2018 21:55:01 +0200 Subject: [PATCH 4/4] movend comments to related api call --- src/morphAttrs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/morphAttrs.js b/src/morphAttrs.js index de58214..2a0ed63 100644 --- a/src/morphAttrs.js +++ b/src/morphAttrs.js @@ -19,13 +19,13 @@ export default function morphAttrs(fromNode, toNode) { 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 = fromNode.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 fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); } } else {