From 790f2b53131f2468ee9b7884a4a361ae6f4d6cc0 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Mon, 20 Aug 2018 22:39:32 -0300 Subject: [PATCH 1/2] Remove an undefined attribute instead of setting it to "undefined" (string) --- src/shared/dom.js | 8 ++++---- test/runtime/samples/set-undefined-attr/_config.js | 5 +++++ test/runtime/samples/set-undefined-attr/main.html | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 test/runtime/samples/set-undefined-attr/_config.js create mode 100644 test/runtime/samples/set-undefined-attr/main.html diff --git a/src/shared/dom.js b/src/shared/dom.js index d428e92f1c4a..5e152b9c1bc7 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 000000000000..d5aa293bf22e --- /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 000000000000..09e63ca45be6 --- /dev/null +++ b/test/runtime/samples/set-undefined-attr/main.html @@ -0,0 +1,14 @@ +
+ + From 89c1fa675bc4eefb322c519caca2fceb18b6c83c Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Mon, 20 Aug 2018 23:02:24 -0300 Subject: [PATCH 2/2] Also check for null-valued attributes --- src/shared/dom.js | 2 +- .../samples/dont-use-dataset-in-legacy/expected-bundle.js | 7 ++++++- test/js/samples/dont-use-dataset-in-svg/expected-bundle.js | 7 ++++++- test/js/samples/input-files/expected-bundle.js | 7 ++++++- test/js/samples/input-range/expected-bundle.js | 7 ++++++- .../input-without-blowback-guard/expected-bundle.js | 7 ++++++- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/shared/dom.js b/src/shared/dom.js index 5e152b9c1bc7..51281409a776 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -82,7 +82,7 @@ export function removeListener(node, event, handler) { } export function setAttribute(node, attribute, value) { - if (value === undefined) removeAttribute(node, attribute); + if (value == null) removeAttribute(node, attribute); else node.setAttribute(attribute, value); } diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js index 30890b83a3be..9ca1b1926622 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js +++ b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js @@ -22,7 +22,12 @@ function createText(data) { } function setAttribute(node, attribute, value) { - node.setAttribute(attribute, value); + if (value == null) removeAttribute(node, attribute); + else node.setAttribute(attribute, value); +} + +function removeAttribute(node, attribute) { + node.removeAttribute(attribute); } function blankObject() { diff --git a/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js b/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js index 9c006e287017..41926764189e 100644 --- a/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js +++ b/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js @@ -22,7 +22,12 @@ function createSvgElement(name) { } function setAttribute(node, attribute, value) { - node.setAttribute(attribute, value); + if (value == null) removeAttribute(node, attribute); + else node.setAttribute(attribute, value); +} + +function removeAttribute(node, attribute) { + node.removeAttribute(attribute); } function blankObject() { diff --git a/test/js/samples/input-files/expected-bundle.js b/test/js/samples/input-files/expected-bundle.js index 1a6376f19353..4e5169462536 100644 --- a/test/js/samples/input-files/expected-bundle.js +++ b/test/js/samples/input-files/expected-bundle.js @@ -26,7 +26,12 @@ function removeListener(node, event, handler) { } function setAttribute(node, attribute, value) { - node.setAttribute(attribute, value); + if (value == null) removeAttribute(node, attribute); + else node.setAttribute(attribute, value); +} + +function removeAttribute(node, attribute) { + node.removeAttribute(attribute); } function blankObject() { diff --git a/test/js/samples/input-range/expected-bundle.js b/test/js/samples/input-range/expected-bundle.js index f9b53e91a5da..1711ee53bbb3 100644 --- a/test/js/samples/input-range/expected-bundle.js +++ b/test/js/samples/input-range/expected-bundle.js @@ -26,7 +26,12 @@ function removeListener(node, event, handler) { } function setAttribute(node, attribute, value) { - node.setAttribute(attribute, value); + if (value == null) removeAttribute(node, attribute); + else node.setAttribute(attribute, value); +} + +function removeAttribute(node, attribute) { + node.removeAttribute(attribute); } function toNumber(value) { diff --git a/test/js/samples/input-without-blowback-guard/expected-bundle.js b/test/js/samples/input-without-blowback-guard/expected-bundle.js index c3abad14fe0b..817aa1e401d0 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -26,7 +26,12 @@ function removeListener(node, event, handler) { } function setAttribute(node, attribute, value) { - node.setAttribute(attribute, value); + if (value == null) removeAttribute(node, attribute); + else node.setAttribute(attribute, value); +} + +function removeAttribute(node, attribute) { + node.removeAttribute(attribute); } function blankObject() {