Skip to content

Commit 1e8850d

Browse files
committed
swap set and removal order of attributes/style properties
1 parent e4b4791 commit 1e8850d

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

render/render.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -710,22 +710,24 @@ module.exports = function() {
710710
if ("selectedIndex" in attrs) setAttr(vnode, "selectedIndex", null, attrs.selectedIndex, undefined)
711711
}
712712
function updateAttrs(vnode, old, attrs, ns) {
713-
if (old && old === attrs) {
714-
console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major")
715-
}
716-
if (attrs != null) {
717-
for (var key in attrs) {
718-
setAttr(vnode, key, old && old[key], attrs[key], ns)
719-
}
720-
}
713+
// Some attributes may NOT be case-sensitive (e.g. data-***),
714+
// so removal should be done first to prevent accidental removal for newly setting values.
721715
var val
722716
if (old != null) {
717+
if (old === attrs) {
718+
console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major")
719+
}
723720
for (var key in old) {
724721
if (((val = old[key]) != null) && (attrs == null || attrs[key] == null)) {
725722
removeAttr(vnode, key, val, ns)
726723
}
727724
}
728725
}
726+
if (attrs != null) {
727+
for (var key in attrs) {
728+
setAttr(vnode, key, old && old[key], attrs[key], ns)
729+
}
730+
}
729731
}
730732
function isFormAttribute(vnode, attr) {
731733
return attr === "value" || attr === "checked" || attr === "selectedIndex" || attr === "selected" && vnode.dom === activeElement(vnode.dom) || vnode.tag === "option" && vnode.dom.parentNode === activeElement(vnode.dom)
@@ -767,6 +769,15 @@ module.exports = function() {
767769
}
768770
} else {
769771
// Both old & new are (different) objects.
772+
// Remove style properties that no longer exist
773+
// Style properties may have two cases(dash-case and camelCase),
774+
// so removal should be done first to prevent accidental removal for newly setting values.
775+
for (var key in old) {
776+
if (old[key] != null && style[key] == null) {
777+
if (key.includes("-")) element.style.removeProperty(key)
778+
else element.style[key] = ""
779+
}
780+
}
770781
// Update style properties that have changed
771782
for (var key in style) {
772783
var value = style[key]
@@ -775,13 +786,6 @@ module.exports = function() {
775786
else element.style[key] = value
776787
}
777788
}
778-
// Remove style properties that no longer exist
779-
for (var key in old) {
780-
if (old[key] != null && style[key] == null) {
781-
if (key.includes("-")) element.style.removeProperty(key)
782-
else element.style[key] = ""
783-
}
784-
}
785789
}
786790
}
787791

0 commit comments

Comments
 (0)