mirror of https://github.com/sveltejs/svelte
fix: apply class/style directives after attributes (#13535)
fixes #13270 by resetting the has_call boolean to false to style/class attributes, which means we're not creating a separate template effect for the attribute, instead they're added to the common template effect in which style/class directives are also added to laterpull/13540/head
parent
2b0741fa11
commit
8148e63ced
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: apply class/style directives after attributes
|
@ -0,0 +1,37 @@
|
|||||||
|
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, [
|
||||||
|
'updated class attribute',
|
||||||
|
'updated class directive',
|
||||||
|
'updated style attribute',
|
||||||
|
'updated style directive'
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.ok(div.classList.contains('dark'));
|
||||||
|
assert.ok(div.classList.contains('small'));
|
||||||
|
|
||||||
|
assert.equal(div2.getAttribute('style'), 'background: green; color: green;');
|
||||||
|
|
||||||
|
flushSync(() => button?.click());
|
||||||
|
|
||||||
|
assert.deepEqual(logs, [
|
||||||
|
'updated class attribute',
|
||||||
|
'updated class directive',
|
||||||
|
'updated style attribute',
|
||||||
|
'updated style directive',
|
||||||
|
'updated class attribute',
|
||||||
|
'updated style attribute'
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.ok(div.classList.contains('dark'));
|
||||||
|
assert.ok(div.classList.contains('big'));
|
||||||
|
|
||||||
|
assert.equal(div2.getAttribute('style'), 'background: red; color: green;');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,23 @@
|
|||||||
|
<script>
|
||||||
|
let value = $state(0);
|
||||||
|
function dark(){
|
||||||
|
console.log('updated class directive');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
function get_class(){
|
||||||
|
console.log('updated class attribute');
|
||||||
|
return value % 2 ? 'big' : 'small';
|
||||||
|
}
|
||||||
|
function color(){
|
||||||
|
console.log('updated style directive');
|
||||||
|
return "green";
|
||||||
|
}
|
||||||
|
function get_style(){
|
||||||
|
console.log('updated style attribute');
|
||||||
|
return value % 2 ? 'background: red' : 'background: green';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class:dark={dark()} class={get_class()}></div>
|
||||||
|
<div style:color={color()} style={get_style()}></div>
|
||||||
|
<button onclick={()=> value++}>switch</button>
|
Loading…
Reference in new issue