Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply class/style directives after attributes #13338

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
test({ target, logs, assert }) {
const div = target.querySelector('div');
const button = target.querySelector('button');

assert.deepEqual(logs, ['updated attribute', 'updated directive']);

assert.ok(div?.classList.contains('dark'));
assert.ok(div?.classList.contains('small'));

flushSync(() => button?.click());
assert.deepEqual(logs, ['updated attribute', 'updated directive', 'updated attribute']);
assert.ok(div?.classList.contains('dark'));
assert.ok(div?.classList.contains('big'));
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script>
let value = $state(0);

function dark(){
console.log('updated directive');
return true;
}

function get_class(){
console.log('updated attribute');
return value % 2 ? 'big' : 'small';
}
</script>

<div class:dark={dark()} class={get_class()}></div>
<button onclick={()=> value++}>switch</button>
Loading