-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed namespaced attributes not updating #125
fixed namespaced attributes not updating #125
Conversation
@patrick-steele-idem |
@AndyOGo is it possible to demonstrate this with a test (one that fails under current version but passes under proposed)? I know @patrick-steele-idem changed jobs recently, so he may not have the time to look into this. |
@AutoSponge Well, the thing is that, I faced this issue in Firefox at a customer of mine for axa-ch-webhub-cloud/pattern-library#411. Here are the copies from my screencasts (but baked by May I ask, aren't the links I provided form the official specs making the point clear enough? And I supplied the same Bugfix to nanomorph |
PS. The reason this works in Chrome, is that SVG 2 drop |
PPS: I also updated the related MDN article here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR needs a test which can be run cross-browser to ensure it will not fail existing functionality. Fixing firefox but breaking IE is not an option.
This also serves to explain to other developers what's expected for a given mutation.
@@ -16,9 +16,15 @@ export default function morphAttrs(fromNode, toNode) { | |||
attrValue = attr.value; | |||
|
|||
if (attrNamespaceURI) { | |||
attrName = attr.localName || attrName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use || attrName
because IE doesn't seem to support .localName
see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback, very appreciated.
About which version of IE are we speaking? (IE9 supports localName, see).
Microsoft officially stopped to support old IE versions until version 11
My point is that the setAttributeNS
API is called with the wrong argument and I provided the official W3C specifications. May I ask you to study them yourself, look up all the technical definitions in the official DOM API glossary and then decide for yourself if I'm right or wrong.
src/morphAttrs.js
Outdated
// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AutoSponge
I just inlined the attrName fallback just for getAttributeNS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndyOGo are you saying these two blocks are different?
current
attrName = attr.localName || attrName;
fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName);
this PR
var attrLocalName = attr.localName;
fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrLocalName || attrName);
Because I'm not seeing it. I'm still confused as to exactly what you think this fixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No with my last commit I restored the original getAttributeNS
function call with a fallback to attrName
if attr.localName
is not defined.
But the line below using setAttributeNS
has changed to never use attr.localName
.
src/morphAttrs.js
Outdated
// 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) { | ||
fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AutoSponge
Since I don't overwrite attrName
with attr.localName || attrName
anymore, setAttributeNS
will always only use the full qualified attribute name, including it's namespace.
if (fromValue !== attrValue) { | ||
// but setAttributeNS requires the fully qualified name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also moved my complementary comments to the related API calls
@AutoSponge Before the local variable And please stop trolling and giving me bad reputation, I develop frontend projects since decades, have studied all ECMA script specs starting with version 1 fully by myself. |
xlink:href is deprecated: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href Do not use. Without a test case to demonstrate how this affects morphdom, I'm keeping it closed. I've already blocked you but I will report if you continue this harassment and waste of my time. |
Agreed I'm sorry if you interpret my comments as harassment, they don't meant to be. My main idea is to help and to suggest an spec-conformant implementation regarding the usage of Unfortunately cooperation with you is not a perfect match and therefore I can't help |
fixes #124
Using SVG sprites with
<use xlink:href="" />
will not update the icon.The reason is that
getAttributeNS
andsetAttributeNS
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 thelocalName
, i.e.getAttributeNS('https://www.w3.org/1999/foo', 'bar');
setAttributeNS
expects it's fully qualified name, i.e.setAttributeNS('https://www.w3.org/1999/foo', 'foo:bar');