Skip to content

Commit 4347b30

Browse files
committed
fix, enhance test, explain
1 parent 705156a commit 4347b30

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ export function prop(props, key, flags, fallback) {
296296
var is_entry_props = STATE_SYMBOL in props || LEGACY_PROPS in props;
297297

298298
var setter =
299-
get_descriptor(props, key)?.set ?? (is_entry_props ? (v) => (props[key] = v) : undefined);
299+
get_descriptor(props, key)?.set ??
300+
(is_entry_props && bindable ? (v) => (props[key] = v) : undefined);
300301

301302
var fallback_value = /** @type {V} */ (fallback);
302303
var fallback_dirty = true;
@@ -322,7 +323,7 @@ export function prop(props, key, flags, fallback) {
322323
}
323324

324325
prop_value = get_fallback();
325-
if (setter && (!is_entry_props || bindable)) setter(prop_value);
326+
if (setter) setter(prop_value);
326327
}
327328

328329
/** @type {() => V} */

packages/svelte/tests/runtime-runes/samples/mount-props-updates/_config.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ export default test({
55
test({ assert, target }) {
66
assert.htmlEqual(
77
target.innerHTML,
8+
// Even thought we're in runes mode, the buz fallback propagates back up in this case
89
`
9-
<button>reset</button>
10+
<button>reset</button> foo baz buz
1011
<div><button>update</button> foo bar baz buz</div>
1112
<div><button>update</button> foo bar baz buz</div>
1213
`
@@ -19,8 +20,9 @@ export default test({
1920
flushSync();
2021
assert.htmlEqual(
2122
target.innerHTML,
23+
// bar is not set in the parent because it's a readonly property
2224
`
23-
<button>reset</button>
25+
<button>reset</button> foo 3 4
2426
<div><button>update</button> 1 2 3 4</div>
2527
<div><button>update</button> 1 2 3 4</div>
2628
`
@@ -30,10 +32,13 @@ export default test({
3032
flushSync();
3133
assert.htmlEqual(
3234
target.innerHTML,
35+
// Because foo is a readonly property, component.svelte diverges locally from it,
36+
// and the passed in property keeps the initial value of foo. This is why it stays
37+
// at 1, because foo is not updated to a different value.
3338
`
34-
<button>reset</button>
35-
<div><button>update</button> foo bar baz buz</div>
36-
<div><button>update</button> foo bar baz buz</div>
39+
<button>reset</button> foo bar baz buz
40+
<div><button>update</button> 1 bar baz buz</div>
41+
<div><button>update</button> 1 bar baz buz</div>
3742
`
3843
);
3944
}

packages/svelte/tests/runtime-runes/samples/mount-props-updates/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
props.baz = 'baz';
2626
props.buz = 'buz';
2727
}}>reset</button
28-
>
28+
> {props.foo} {props.bar} {props.baz} {props.buz}
2929
<div bind:this={div1}></div>
3030
<div bind:this={div2}></div>

0 commit comments

Comments
 (0)