Skip to content

Commit

Permalink
tweak behavior to be more inline with what we do in case of props for…
Browse files Browse the repository at this point in the history
… components in the template
  • Loading branch information
dummdidumm committed Nov 14, 2024
1 parent 4347b30 commit 06c5023
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/svelte/src/internal/client/reactivity/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ const spread_props_handler = {
}
},
has(target, key) {
if (key === STATE_SYMBOL) return false;
// To prevent a false positive `is_entry_props` in the `prop` function
if (key === STATE_SYMBOL || key === LEGACY_PROPS) return false;

for (let p of target.props) {
if (is_function(p)) p = p();
Expand Down Expand Up @@ -297,7 +298,7 @@ export function prop(props, key, flags, fallback) {

var setter =
get_descriptor(props, key)?.set ??
(is_entry_props && bindable ? (v) => (props[key] = v) : undefined);
(is_entry_props && bindable && key in props ? (v) => (props[key] = v) : undefined);

var fallback_value = /** @type {V} */ (fallback);
var fallback_dirty = true;
Expand All @@ -318,7 +319,7 @@ export function prop(props, key, flags, fallback) {
};

if (prop_value === undefined && fallback !== undefined) {
if (setter && runes && !is_entry_props) {
if (setter && runes) {
e.props_invalid_value(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default test({
test({ assert, target }) {
assert.htmlEqual(
target.innerHTML,
// Even thought we're in runes mode, the buz fallback propagates back up in this case
// The buz fallback does not propagate back up
`
<button>reset</button> foo baz buz
<button>reset</button> foo baz
<div><button>update</button> foo bar baz buz</div>
<div><button>update</button> foo bar baz buz</div>
`
Expand All @@ -21,8 +21,10 @@ export default test({
assert.htmlEqual(
target.innerHTML,
// bar is not set in the parent because it's a readonly property
// baz is not set in the parent because while it's a bindable property,
// it wasn't set initially so it's treated as a readonly proeprty
`
<button>reset</button> foo 3 4
<button>reset</button> foo 3
<div><button>update</button> 1 2 3 4</div>
<div><button>update</button> 1 2 3 4</div>
`
Expand Down

0 comments on commit 06c5023

Please sign in to comment.