Skip to content

Commit 4fbd2a6

Browse files
trueadmdummdidumm
andauthored
fix: ensure props internally untracks current_value on sets (#13859)
* fix: ensure props internally untracks current_value on sets * Update packages/svelte/src/internal/client/reactivity/props.js --------- Co-authored-by: Simon H <[email protected]>
1 parent 60dcffb commit 4fbd2a6

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

.changeset/short-jokes-speak.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: ensure props internally untracks current_value on sets

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,6 @@ export function prop(props, key, flags, fallback) {
373373
if (!immutable) current_value.equals = safe_equals;
374374

375375
return function (/** @type {any} */ value, /** @type {boolean} */ mutation) {
376-
var current = get(current_value);
377-
378376
// legacy nonsense — need to ensure the source is invalidated when necessary
379377
// also needed for when handling inspect logic so we can inspect the correct source signal
380378
if (is_signals_recorded) {
@@ -398,12 +396,11 @@ export function prop(props, key, flags, fallback) {
398396
if (fallback_used && fallback_value !== undefined) {
399397
fallback_value = new_value;
400398
}
401-
get(current_value); // force a synchronisation immediately
399+
untrack(() => get(current_value)); // force a synchronisation immediately
402400
}
403401

404402
return value;
405403
}
406-
407-
return current;
404+
return get(current_value);
408405
};
409406
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, logs, target }) {
6+
const btn = target.querySelector('button');
7+
8+
flushSync(() => {
9+
btn?.click();
10+
btn?.click();
11+
btn?.click();
12+
});
13+
14+
assert.deepEqual(logs, ['effect']);
15+
}
16+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
let {display = true} = $props();
3+
4+
$effect(()=>{
5+
display = true;
6+
console.log("effect")
7+
});
8+
</script>
9+
10+
<button onclick={() => display = !display} >display</button>

0 commit comments

Comments
 (0)