Skip to content

Commit

Permalink
Always keep key in vnode.attrs if it exists
Browse files Browse the repository at this point in the history
Because vnode.attrs is never null by commit f9e5163
  • Loading branch information
kfule committed Feb 10, 2023
1 parent e876753 commit 51fa771
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
24 changes: 8 additions & 16 deletions render/hyperscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,23 @@ function execSelector(state, vnode) {
var className = hasClass ? attrs.class : attrs.className

vnode.tag = state.tag
vnode.attrs = {}

if (!isEmpty(state.attrs) && !isEmpty(attrs)) {
if (!isEmpty(state.attrs)) {
var newAttrs = {}

for (var key in attrs) {
if (hasOwn.call(attrs, key)) newAttrs[key] = attrs[key]
}

attrs = newAttrs
}
vnode.attrs = newAttrs

for (var key in state.attrs) {
if (hasOwn.call(state.attrs, key) && key !== "className" && !hasOwn.call(attrs, key)){
attrs[key] = state.attrs[key]
for (var key in state.attrs) {
if (hasOwn.call(state.attrs, key) && key !== "className" && !hasOwn.call(vnode.attrs, key)) {
vnode.attrs[key] = state.attrs[key]
}
}
}
if (className != null || state.attrs.className != null) attrs.className =
if (className != null || state.attrs.className != null) vnode.attrs.className =
className != null
? state.attrs.className != null
? String(state.attrs.className) + " " + String(className)
Expand All @@ -62,14 +61,7 @@ function execSelector(state, vnode) {
? state.attrs.className
: null

if (hasClass) attrs.class = null

for (var key in attrs) {
if (hasOwn.call(attrs, key) && key !== "key") {
vnode.attrs = attrs
break
}
}
if (hasClass) vnode.attrs.class = null

return vnode
}
Expand Down
4 changes: 2 additions & 2 deletions render/tests/test-hyperscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ o.spec("hyperscript", function() {
var vnode = m("div", {key:"a"})

o(vnode.tag).equals("div")
o(vnode.attrs).deepEquals({})
o(vnode.attrs).deepEquals({key:"a"})
o(vnode.key).equals("a")
})
o("handles many attrs", function() {
Expand Down Expand Up @@ -343,7 +343,7 @@ o.spec("hyperscript", function() {
var vnode = m("custom-element", {key:"a"})

o(vnode.tag).equals("custom-element")
o(vnode.attrs).deepEquals({})
o(vnode.attrs).deepEquals({key:"a"})
o(vnode.key).equals("a")
})
o("handles many attrs", function() {
Expand Down

0 comments on commit 51fa771

Please sign in to comment.