Skip to content

fix: improve internal_set versioning mechanic #15724

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-planes-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: improve internal_set versioning mechanic
3 changes: 2 additions & 1 deletion packages/svelte/src/internal/client/reactivity/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ export function internal_set(source, value) {
}

source.v = value;
source.wv = increment_write_version();

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

source.wv = increment_write_version();

mark_reactions(source, DIRTY);

// It's possible that the current reaction might not have up-to-date dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from '../../test';

export default test({
html: `true true`,

test({ assert, target, window }) {}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
import { expect2, createAppState } from "./util.svelte.js"

const result = createAppState({ source: () => "wrong" });
result.onChange("right");
const expect1 = result.value === "right";
</script>

{expect1} {expect2}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const createAppState = (options) => {
const source = $derived(options.source());
let value = $derived(source);

return {
get value() {
return value;
},
onChange(nextValue) {
value = nextValue;
}
};
};

const result = createAppState({ source: () => 'wrong' });
result.onChange('right');
export const expect2 = result.value === 'right';