Skip to content

Commit

Permalink
fix: inline style value become undefined (#8517)
Browse files Browse the repository at this point in the history
fixes #8462

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
  • Loading branch information
xxkl1 and dummdidumm committed Apr 19, 2023
1 parent 6bbae50 commit 32153e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export function attr(node: Element, attribute: string, value?: string) {
else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value);
}

/**
/**
* List of attributes that should always be set through the attr method,
* because updating them through the property setter doesn't work reliably.
* In the example of `width`/`height`, the problem is that the setter only
Expand Down Expand Up @@ -641,7 +641,7 @@ export function set_input_type(input, type) {
}

export function set_style(node, key, value, important) {
if (value === null) {
if (value == null) {
node.style.removeProperty(key);
} else {
node.style.setProperty(key, value, important ? 'important' : '');
Expand Down
11 changes: 11 additions & 0 deletions test/runtime/samples/inline-style-become-undefined/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
async test({ assert, target, window }) {
const div = target.querySelector('div');
const click = new window.MouseEvent('click');

assert.htmlEqual(target.innerHTML, '<div style="background: red;"></div>');
await div.dispatchEvent(click);
await Promise.resolve();
assert.htmlEqual(target.innerHTML, '<div style=""></div>');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
let bg = "red";
const handle = () => {
bg = undefined;
};
</script>

<div style:background={bg} on:click={handle}></div>

0 comments on commit 32153e3

Please sign in to comment.