mirror of https://github.com/sveltejs/svelte
fix: separate `template_effect` for dynamic class/style directive with dynamic attributes (#13171)
* fix: separate `template_effect` for dynamic class/style directive with dynamic attributes * fix: only move to `init` if it `has_call` * fix: initialize spread `needs_isolation` based on if there are directives with `has_call` * fix: revert splitting templates and generate deriveds instead * small tweaks --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/13257/head
parent
6b69de79fa
commit
3864229418
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: separate `template_effect` for dynamic class/style directive with dynamic attributes
|
@ -0,0 +1,19 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ target, logs, assert }) {
|
||||
const [div, div2] = target.querySelectorAll('div');
|
||||
const button = target.querySelector('button');
|
||||
|
||||
assert.deepEqual(logs, ['called', 'called']);
|
||||
|
||||
// this is to assert that the order of the attributes is still not relevant
|
||||
// and directives take precedence over generic attribute
|
||||
assert.equal(div.classList.contains('dark'), false);
|
||||
assert.equal(div2.style.color, 'red');
|
||||
|
||||
flushSync(() => button?.click());
|
||||
assert.deepEqual(logs, ['called', 'called']);
|
||||
}
|
||||
});
|
@ -0,0 +1,25 @@
|
||||
<script>
|
||||
let value = $state(0);
|
||||
|
||||
function dark(){
|
||||
console.log('called')
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_class(){
|
||||
return 'dark';
|
||||
}
|
||||
|
||||
function color(){
|
||||
console.log('called')
|
||||
return 'red';
|
||||
}
|
||||
|
||||
function get_style(){
|
||||
return 'color: green';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class:dark={dark()} class={get_class()}></div>
|
||||
<div style:color={color()} style={get_style()}></div>
|
||||
<button onclick={()=> value++}>{value}</button>
|
Loading…
Reference in new issue