Skip to content

Commit bdc0200

Browse files
trueadmpaoloricciutiRich-Harris
authored
fix: reset dependency read versions after reaction execution (#14964)
* fix: reset dependency read versions after reaction execution * fix: reset dependency read versions after reaction execution * fix: reset dependency read versions after reaction execution * fix: reset dependency read versions after reaction execution * fix: reset dependency read versions after reaction execution * chore: add test * changeset --------- Co-authored-by: paoloricciuti <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent b7400ae commit bdc0200

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

.changeset/fifty-chefs-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: reset dependency read versions after reaction execution

packages/svelte/src/internal/client/runtime.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,14 @@ export function update_reaction(reaction) {
434434
deps.length = skipped_deps;
435435
}
436436

437+
// If we are returning to an previous reaction then
438+
// we need to increment the read version to ensure that
439+
// any dependencies in this reaction aren't marked with
440+
// the same version
441+
if (previous_reaction !== null) {
442+
read_version++;
443+
}
444+
437445
return result;
438446
} finally {
439447
new_deps = previous_deps;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
const { label = 0, size = 0 } = $props();
3+
4+
const title = $derived(size.toString());
5+
</script>
6+
7+
<p {title}>{label}</p>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ok, test } from '../../test';
2+
import { flushSync } from 'svelte';
3+
4+
export default test({
5+
html: `<button></button><p title="0">0</p>`,
6+
7+
async test({ assert, target }) {
8+
const p = target.querySelector('p');
9+
const btn = target.querySelector('button');
10+
flushSync(() => {
11+
btn?.click();
12+
});
13+
assert.equal(p?.innerHTML, '1');
14+
flushSync(() => {
15+
btn?.click();
16+
});
17+
assert.equal(p?.innerHTML, '2');
18+
}
19+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import Component from "./Component.svelte";
3+
4+
let props = $state({
5+
label: 0,
6+
size: 0,
7+
});
8+
9+
let filteredProps = $state();
10+
11+
$effect.pre(() => {
12+
filteredProps = $state.snapshot(props);
13+
});
14+
</script>
15+
16+
<button onclick={()=>props.label++}></button>
17+
18+
<Component {...filteredProps} />

0 commit comments

Comments
 (0)