tweak behavior to be more inline with what we do in case of props for components in the template

pull/14210/head
Simon Holthausen 2 years ago
parent 4347b3094b
commit 06c5023007

@ -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();
@ -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;
@ -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);
}

@ -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>
`
@ -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>
`

Loading…
Cancel
Save