mirror of https://github.com/sveltejs/svelte
fix: address runtime effect issues (#9417)
* Fix runtime effect issues * Prettier * Add changeset * Fix operations * Update .changeset/khaki-mails-draw.md * more tweaks * more tweaks --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>pull/9427/head
parent
8798f3b1e7
commit
17e6c4f834
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: tighten up signals implementation
|
@ -0,0 +1,13 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>10</button>`,
|
||||
ssrHtml: `<button>0</button>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<button>10</button>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
class Counter {
|
||||
count = $state(0);
|
||||
|
||||
constructor() {
|
||||
$effect(() => {
|
||||
this.count = 10;
|
||||
});
|
||||
}
|
||||
}
|
||||
const counter = new Counter();
|
||||
</script>
|
||||
|
||||
<button on:click={() => counter.count++}>{counter.count}</button>
|
@ -0,0 +1,13 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>10</button>`,
|
||||
ssrHtml: `<button>0</button>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<button>10</button>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
<script>
|
||||
class Counter {
|
||||
#count = $state(0);
|
||||
|
||||
constructor() {
|
||||
$effect(() => {
|
||||
this.#count = 10;
|
||||
});
|
||||
}
|
||||
|
||||
getCount() {
|
||||
return this.#count;
|
||||
}
|
||||
|
||||
increment() {
|
||||
this.#count++;
|
||||
}
|
||||
}
|
||||
const counter = new Counter();
|
||||
</script>
|
||||
|
||||
<button on:click={() => counter.increment()}>{counter.getCount()}</button>
|
@ -0,0 +1,19 @@
|
||||
import { test } from '../../test';
|
||||
import { flushSync } from 'svelte';
|
||||
|
||||
export default test({
|
||||
get props() {
|
||||
return { log: [] };
|
||||
},
|
||||
|
||||
async test({ assert, target, component }) {
|
||||
const [b1] = target.querySelectorAll('button');
|
||||
flushSync(() => {
|
||||
b1.click();
|
||||
});
|
||||
flushSync(() => {
|
||||
b1.click();
|
||||
});
|
||||
assert.deepEqual(component.log, ['init 0', 'cleanup 2', 'init 2', 'cleanup 4', 'init 4']);
|
||||
}
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
const {log} = $props();
|
||||
|
||||
let count = $state(0);
|
||||
|
||||
$effect(() => {
|
||||
let double = $derived(count * 2)
|
||||
|
||||
log.push('init ' + double);
|
||||
|
||||
return () => {
|
||||
log.push('cleanup ' + double);
|
||||
};
|
||||
})
|
||||
</script>
|
||||
|
||||
<button on:click={() => count++ }>Click</button>
|
Loading…
Reference in new issue