diff --git a/src/shared/dom.js b/src/shared/dom.js index d428e92f1c..5e152b9c1b 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -82,7 +82,8 @@ export function removeListener(node, event, handler) { } export function setAttribute(node, attribute, value) { - node.setAttribute(attribute, value); + if (value === undefined) removeAttribute(node, attribute); + else node.setAttribute(attribute, value); } export function setAttributes(node, attributes) { @@ -90,8 +91,7 @@ export function setAttributes(node, attributes) { if (key in node) { node[key] = attributes[key]; } else { - if (attributes[key] === undefined) removeAttribute(node, key); - else setAttribute(node, key, attributes[key]); + setAttribute(node, key, attributes[key]); } } } @@ -238,4 +238,4 @@ export function addResizeListener(element, fn) { element.removeChild(object); } }; -} \ No newline at end of file +} diff --git a/test/runtime/samples/set-undefined-attr/_config.js b/test/runtime/samples/set-undefined-attr/_config.js new file mode 100644 index 0000000000..d5aa293bf2 --- /dev/null +++ b/test/runtime/samples/set-undefined-attr/_config.js @@ -0,0 +1,5 @@ +export default { + 'skip-ssr': true, + + html: '
' +}; diff --git a/test/runtime/samples/set-undefined-attr/main.html b/test/runtime/samples/set-undefined-attr/main.html new file mode 100644 index 0000000000..09e63ca45b --- /dev/null +++ b/test/runtime/samples/set-undefined-attr/main.html @@ -0,0 +1,14 @@ +
+ +