mirror of https://github.com/sveltejs/svelte
Not all batches will flush right after being activated, some will be activated and then `get` is called on a signal. In that case the value was wrong because we did not apply the changes of that batch. By doing `this.apply()` during `activate()` we ensure we do, which fixes (among other things, likely) a forking bug where old values where sneaking in. Fixes #17079pull/17098/head
parent
b7625fd42c
commit
02f8d07364
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure fork always accesses correct values
|
||||
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
let { x } = $props();
|
||||
console.log(x);
|
||||
await Promise.resolve();
|
||||
console.log(x);
|
||||
</script>
|
||||
|
||||
{x}
|
||||
@ -0,0 +1,12 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target, logs }) {
|
||||
const btn = target.querySelector('button');
|
||||
|
||||
btn?.click();
|
||||
await new Promise((r) => setTimeout(r, 2));
|
||||
assert.htmlEqual(target.innerHTML, `<button>fork</button> universe`);
|
||||
assert.deepEqual(logs, ['universe', 'universe']);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
import { fork } from 'svelte';
|
||||
import Child from './Child.svelte';
|
||||
let x = $state('world');
|
||||
</script>
|
||||
|
||||
<button onclick={async () => {
|
||||
const f = fork(() => {
|
||||
x = 'universe'
|
||||
});
|
||||
await new Promise(r => setTimeout(r));
|
||||
f.commit();
|
||||
}}>fork</button>
|
||||
|
||||
{#if x === 'universe'}
|
||||
<Child {x} />
|
||||
{/if}
|
||||
Loading…
Reference in new issue