mirror of https://github.com/sveltejs/svelte
fix: don't set derived values during time traveling (#17163)
* chore: failing test for derived + fork + block * fix: don't set derived values during time travel * fix: skip no async * fix: only set `derived.v` outside a fork * chore: simplify Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> * tidy up test a bit (missing text makes things confusing in the sandbox) * update comment * tweak --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/17198/merge
parent
9ccbd734f2
commit
056b201d80
@ -0,0 +1,20 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
skip_no_async: true,
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [fork, update] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
fork.click();
|
||||||
|
});
|
||||||
|
flushSync(() => {
|
||||||
|
update.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
const p = target.querySelector('p');
|
||||||
|
|
||||||
|
assert.equal(p?.textContent, 'one');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<script>
|
||||||
|
import { fork } from "svelte";
|
||||||
|
|
||||||
|
let state = $state(0);
|
||||||
|
let count = $derived(state);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => {
|
||||||
|
fork(() => {
|
||||||
|
state++;
|
||||||
|
});
|
||||||
|
}}>fork</button>
|
||||||
|
|
||||||
|
<button onclick={() => {
|
||||||
|
state++;
|
||||||
|
}}>update</button>
|
||||||
|
|
||||||
|
{#if count === 1}
|
||||||
|
<p>one</p>
|
||||||
|
{/if}
|
||||||
Loading…
Reference in new issue