Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: ensure props internally untracks current_value on sets #13859

Merged
merged 2 commits into from
Oct 24, 2024
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/short-jokes-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure props internally untracks current_value on sets
7 changes: 2 additions & 5 deletions packages/svelte/src/internal/client/reactivity/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,6 @@ export function prop(props, key, flags, fallback) {
if (!immutable) current_value.equals = safe_equals;

return function (/** @type {any} */ value, /** @type {boolean} */ mutation) {
var current = get(current_value);

// legacy nonsense — need to ensure the source is invalidated when necessary
// also needed for when handling inspect logic so we can inspect the correct source signal
if (is_signals_recorded) {
Expand All @@ -398,12 +396,11 @@ export function prop(props, key, flags, fallback) {
if (fallback_used && fallback_value !== undefined) {
fallback_value = new_value;
}
get(current_value); // force a synchronisation immediately
untrack(() => get(current_value)); // force a synchronisation immediately
}

return value;
}

return current;
return get(current_value);
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
test({ assert, logs, target }) {
const btn = target.querySelector('button');

flushSync(() => {
btn?.click();
btn?.click();
btn?.click();
});

assert.deepEqual(logs, ['effect']);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
let {display = true} = $props();

$effect(()=>{
display = true;
console.log("effect")
});
</script>

<button onclick={() => display = !display} >display</button>