Don't lose `class:` directive classes on an element with `{...spread}` attributes when updating (#3781)

* include all class: directive updates on elements with spreads (#3421)

* add test

* update changelog
pull/3789/head
Conduitry 5 years ago committed by GitHub
parent 8c0c15c3aa
commit 0419039d26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,7 @@
* Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565))
* Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710))
* Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828))
* Don't lose `class:` directive classes on an element with `{...spread}` attributes when updating ([#3421](https://github.com/sveltejs/svelte/issues/3421))
* Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579))
* Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588))
* Fix generated code in specific case involving compound ifs and child components ([#3595](https://github.com/sveltejs/svelte/issue/3595))

@ -809,6 +809,7 @@ export default class ElementWrapper extends Wrapper {
}
add_classes(block: Block) {
const has_spread = this.node.attributes.some(attr => attr.is_spread);
this.node.classes.forEach(class_directive => {
const { expression, name } = class_directive;
let snippet;
@ -824,7 +825,9 @@ export default class ElementWrapper extends Wrapper {
block.chunks.hydrate.push(updater);
if ((dependencies && dependencies.size > 0) || this.class_dependencies.length) {
if (has_spread) {
block.chunks.update.push(updater);
} else if ((dependencies && dependencies.size > 0) || this.class_dependencies.length) {
const all_dependencies = this.class_dependencies.concat(...dependencies);
const condition = changed(all_dependencies);

@ -0,0 +1,7 @@
export default {
html: `<div class='foo bar'>hello</div>`,
test({ assert, component, target }) {
component.blah = 'goodbye';
assert.htmlEqual(target.innerHTML, `<div class='foo bar'>goodbye</div>`);
}
};

@ -0,0 +1,5 @@
<script>
export let blah = 'hello';
</script>
<div class='foo' class:bar={true} {...{}}>{blah}</div>
Loading…
Cancel
Save