Skip to content

Commit 6219282

Browse files
committed
fix: ensure props passed to components via mount are updateable
Fixes #14161
1 parent ea0d80e commit 6219282

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from '../runtime.js';
2121
import { safe_equals } from './equality.js';
2222
import * as e from '../errors.js';
23-
import { BRANCH_EFFECT, LEGACY_DERIVED_PROP, ROOT_EFFECT } from '../constants.js';
23+
import { BRANCH_EFFECT, LEGACY_DERIVED_PROP, ROOT_EFFECT, STATE_SYMBOL } from '../constants.js';
2424
import { proxy } from '../proxy.js';
2525
import { capture_store_binding } from './store.js';
2626
import { legacy_mode_flag } from '../../flags/index.js';
@@ -282,7 +282,11 @@ export function prop(props, key, flags, fallback) {
282282
} else {
283283
prop_value = /** @type {V} */ (props[key]);
284284
}
285-
var setter = get_descriptor(props, key)?.set;
285+
286+
var setter =
287+
get_descriptor(props, key)?.set ??
288+
// Can be the case when someone does `mount(Component, props)` with `let props = $state({...})`
289+
(STATE_SYMBOL in props ? (v) => (props[key] = v) : undefined);
286290

287291
var fallback_value = /** @type {V} */ (fallback);
288292
var fallback_dirty = true;

packages/svelte/src/legacy/legacy-client.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ class Svelte4Component {
104104
set(target, prop, value) {
105105
set(sources.get(prop) ?? add_source(prop, value), value);
106106
return Reflect.set(target, prop, value);
107+
},
108+
getOwnPropertyDescriptor(target, prop) {
109+
// TODO this throws "invalid binding" errors on the component side
110+
const desc = Reflect.getOwnPropertyDescriptor(target, prop);
111+
if (!desc?.configurable) return desc;
112+
return {
113+
get: () => get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop))),
114+
set: (value) => {
115+
set(sources.get(prop) ?? add_source(prop, value), value);
116+
return Reflect.set(target, prop, value);
117+
},
118+
enumerable: desc.enumerable,
119+
configurable: desc.configurable
120+
};
107121
}
108122
}
109123
);

0 commit comments

Comments
 (0)