morphdom icon indicating copy to clipboard operation
morphdom copied to clipboard

Namespaced attributes do not update

Open AndyOGo opened this issue 7 years ago • 3 comments

Using SVG sprites with <use xlink:href="" /> will not update the icon.

The reason is that getAttributeNS and setAttributeNS DOM APIs are inconsistent in it's arguments. E.g.: lets say 'foo:bar' ('foo' being the namespace and 'bar' the local attribute name):

  • getAttributeNS only needs the localName, i.e. getAttributeNS('https://www.w3.org/1999/foo', 'bar');

    getAttributeNS(namespace, localName) https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-localname A local name is the local part of a qualified name. This is called the local part in Namespaces in XML [Namespaces].

  • BUT setAttributeNS expects it's fully qualified name, i.e. setAttributeNS('https://www.w3.org/1999/foo', 'foo:bar');

    setAttributeNS(namespace, qualifiedName, value) https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-qualifiedname A qualified name is the name of an element or attribute defined as the concatenation of a local name (as defined in this specification), optionally preceded by a namespace prefix and colon character. See Qualified Names in Namespaces in XML [Namespaces].

Affected Code https://github.com/patrick-steele-idem/morphdom/blob/master/src/morphAttrs.js#L19-L23

AndyOGo avatar Apr 18 '18 18:04 AndyOGo

same issue for nanomorph https://github.com/choojs/nanomorph/issues/101

AndyOGo avatar Apr 18 '18 18:04 AndyOGo

Issue originally found in https://github.com/axa-ch/patterns-library/pull/411

AndyOGo avatar Apr 18 '18 19:04 AndyOGo

SVG2 has fairly wide support now and IE11 is end-of-life. It may not be worth changing the code but encouraging folks to remove xlink:href.

AutoSponge avatar Apr 22 '20 13:04 AutoSponge