Skip to content

Commit 78e522a

Browse files
committed
fix: improve internal_set versioning mechanic
1 parent 475b5db commit 78e522a

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

.changeset/pretty-planes-visit.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: improve internal_set versioning mechanic

packages/svelte/src/internal/client/reactivity/sources.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ export function internal_set(source, value) {
162162
}
163163

164164
source.v = value;
165-
source.wv = increment_write_version();
166165

167166
if (DEV && tracing_mode_flag) {
168167
source.updated = get_stack('UpdatedAt');
@@ -180,6 +179,8 @@ export function internal_set(source, value) {
180179
set_signal_status(source, (source.f & UNOWNED) === 0 ? CLEAN : MAYBE_DIRTY);
181180
}
182181

182+
source.wv = increment_write_version();
183+
183184
mark_reactions(source, DIRTY);
184185

185186
// It's possible that the current reaction might not have up-to-date dependencies
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `true true`,
5+
6+
test({ assert, target, window }) {}
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import { expect2, createAppState } from "./util.svelte.js"
3+
4+
const result = createAppState({ source: () => "wrong" });
5+
result.onChange("right");
6+
const expect1 = result.value === "right";
7+
</script>
8+
9+
{expect1} {expect2}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const createAppState = (options) => {
2+
const source = $derived(options.source());
3+
let value = $derived(source);
4+
5+
return {
6+
get value() {
7+
return value;
8+
},
9+
onChange(nextValue) {
10+
value = nextValue;
11+
}
12+
};
13+
};
14+
15+
const result = createAppState({ source: () => 'wrong' });
16+
result.onChange('right');
17+
export const expect2 = result.value === 'right';

0 commit comments

Comments
 (0)