Don't use localName to identify tags, if it's not populated#498
Don't use localName to identify tags, if it's not populated#498
Conversation
Don't use localName to identify tags, if it's not populated. I verified this issue on Cobalt 9, but this may also affect IE <=8. https://caniuse.com/?search=localName In browsers that don't populate localName, idom couldn't identify the tag name during patch, and would always think that a different tag was being re-rendered, always recreating DOM nodes rather than reusing them (you can't change the tag name of an existing node). Quick links: Element.localName https://developer.mozilla.org/en-US/docs/Web/API/Element/localName Node.nodeName https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName Element.tagName https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName
Remove runtime Element check and force TypeScript to access `localName`. Changed check to use `??` after I verified that localName is not the empty string
|
|
I'm sorry, I'm not familiar with the idom implementation. I don't understand what I would need to fix. |
|
const d = document.createElement('div');
assert.equal(d.nodeName, 'DIV');
assert.equal(d.localName, 'div');This is particularly important for SVG, which has case-sensitive element names. Eg, In short, everywhere that reads NodeData.nameOrCtor will need to be updated to handle the fact that we can read either a correclty-cased
If you were delete the |
Don't use
localNameto identify tags, if it's not populated.In browsers that don't populate
localName, idom couldn't identify the tag name during patch, and would always think that a different tag was being re-rendered, always recreating DOM nodes rather than reusing them (you can't change the tag name of an existing node).I verified this issue on Cobalt 9, but this may also affect IE <=8 and other old browsers. https://caniuse.com/?search=localName
Quick links:
Element.localNamehttps://developer.mozilla.org/en-US/docs/Web/API/Element/localNameNode.nodeNamehttps://developer.mozilla.org/en-US/docs/Web/API/Node/nodeNameElement.tagNamehttps://developer.mozilla.org/en-US/docs/Web/API/Element/tagName