Skip to content

Commit fb9d3f3

Browse files
committed
Dedicated logic for exotic boolean attributes, fix MithrilJS#2809
1 parent 600a5b8 commit fb9d3f3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

render/render.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ module.exports = function($window) {
687687
if (key[0] === "o" && key[1] === "n") return updateEvent(vnode, key, value)
688688
if (key.slice(0, 6) === "xlink:") vnode.dom.setAttributeNS("http://www.w3.org/1999/xlink", key.slice(6), value)
689689
else if (key === "style") updateStyle(vnode.dom, old, value)
690-
else if (hasPropertyKey(vnode, key, ns)) {
690+
else if (shouldUseProp(vnode, key, value, ns)) {
691691
if (key === "value") {
692692
// Only do the coercion if we're actually going to check the value.
693693
/* eslint-disable no-implicit-coercion */
@@ -717,7 +717,7 @@ module.exports = function($window) {
717717
if (key[0] === "o" && key[1] === "n") updateEvent(vnode, key, undefined)
718718
else if (key === "style") updateStyle(vnode.dom, old, null)
719719
else if (
720-
hasPropertyKey(vnode, key, ns)
720+
shouldUseProp(vnode, key, old, ns)
721721
&& key !== "className"
722722
&& key !== "title" // creates "null" as title
723723
&& !(key === "value" && (
@@ -776,13 +776,19 @@ module.exports = function($window) {
776776
function isLifecycleMethod(attr) {
777777
return attr === "oninit" || attr === "oncreate" || attr === "onupdate" || attr === "onremove" || attr === "onbeforeremove" || attr === "onbeforeupdate"
778778
}
779-
function hasPropertyKey(vnode, key, ns) {
779+
// determine if a vDOM attr should be set as property or attribute
780+
function shouldUseProp(vnode, key, value, ns) {
780781
// Filter out namespaced keys
781782
return ns === undefined && (
782783
// If it's a custom element, just keep it.
783784
vnode.tag.indexOf("-") > -1 || vnode.attrs != null && vnode.attrs.is ||
784785
// If it's a normal element, let's try to avoid a few browser bugs.
785786
key !== "href" && key !== "list" && key !== "form" && key !== "width" && key !== "height"// && key !== "type"
787+
// `m("a[download]")` would otherwilse be set to the string "true"
788+
&& !(key === "download" && value === true)
789+
// `m("[spellcheck=false]")` and `m("[translate=no]")` would otherwise be paradoxically truthy
790+
&& !(key === "spellcheck" && typeof value === "string")
791+
&& !(key === "translate" && typeof value === "string")
786792
// Defer the property check until *after* we check everything.
787793
) && key in vnode.dom
788794
}

0 commit comments

Comments
 (0)