mirror of https://github.com/sveltejs/svelte
fix: bail out of event hoisting when referencing store subscriptions (#12301)
parent
521988c53e
commit
80263770f1
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: bail out of event hoisting when referencing store subscriptions
|
@ -0,0 +1,26 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ assert, target }) {
|
||||
const [b1, b2] = target.querySelectorAll('button');
|
||||
|
||||
b1.click();
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>set new store</button><button>incr</button><pre>0</pre>'
|
||||
);
|
||||
|
||||
b2.click();
|
||||
b2.click();
|
||||
b2.click();
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>set new store</button><button>incr</button><pre>3</pre>'
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
let store = $state();
|
||||
|
||||
function setStore() {
|
||||
store = writable(0, () => {
|
||||
console.log('start');
|
||||
return () => console.log('stop');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={setStore}>set new store</button>
|
||||
<button onclick={() => $store++}>incr</button>
|
||||
|
||||
<pre>{$store}</pre>
|
Loading…
Reference in new issue