mirror of https://github.com/sveltejs/svelte
fix: improve effect over-fire on store subscription init (#10535)
parent
73830596b5
commit
41cdbafc40
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: improve effect over-fire on store subscription init
|
@ -0,0 +1,22 @@
|
||||
import { test } from '../../test';
|
||||
import { log } from './log.js';
|
||||
|
||||
export default test({
|
||||
html: `<button>increment</button>`,
|
||||
|
||||
before_test() {
|
||||
log.length = 0;
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const btn = target.querySelector('button');
|
||||
|
||||
assert.deepEqual(log, [1]);
|
||||
|
||||
await btn?.click();
|
||||
assert.deepEqual(log, [1, 2]);
|
||||
|
||||
await btn?.click();
|
||||
assert.deepEqual(log, [1, 2, 3]);
|
||||
}
|
||||
});
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,18 @@
|
||||
<script>
|
||||
import { untrack } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import { log } from './log';
|
||||
|
||||
const storeCount = writable(0)
|
||||
let count = $state(0);
|
||||
|
||||
$effect(() => {
|
||||
$storeCount;
|
||||
untrack(() => {
|
||||
count++;
|
||||
log.push(count);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<button on:click={() => $storeCount++}>increment</button>
|
Loading…
Reference in new issue