Skip to content

Commit b36329a

Browse files
committed
fix
1 parent 6b0af69 commit b36329a

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

packages/svelte/src/internal/client/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export const EFFECT_HAS_DERIVED = 1 << 19;
2222

2323
export const STATE_SYMBOL = Symbol('$state');
2424
export const STATE_SYMBOL_METADATA = Symbol('$state metadata');
25+
export const LEGACY_PROPS = Symbol('legacy props');
2526
export const LOADING_ATTR_SYMBOL = Symbol('');

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ 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, STATE_SYMBOL } from '../constants.js';
23+
import {
24+
BRANCH_EFFECT,
25+
LEGACY_DERIVED_PROP,
26+
LEGACY_PROPS,
27+
ROOT_EFFECT,
28+
STATE_SYMBOL
29+
} from '../constants.js';
2430
import { proxy } from '../proxy.js';
2531
import { capture_store_binding } from './store.js';
2632
import { legacy_mode_flag } from '../../flags/index.js';
@@ -283,10 +289,12 @@ export function prop(props, key, flags, fallback) {
283289
prop_value = /** @type {V} */ (props[key]);
284290
}
285291

292+
// Can be the case when someone does `mount(Component, props)` with `let props = $state({...})`
293+
// or `createClassComponent(Component, props)`
294+
var is_entry_props = STATE_SYMBOL in props || LEGACY_PROPS in props;
295+
286296
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);
297+
get_descriptor(props, key)?.set ?? (is_entry_props ? (v) => (props[key] = v) : undefined);
290298

291299
var fallback_value = /** @type {V} */ (fallback);
292300
var fallback_dirty = true;
@@ -307,7 +315,7 @@ export function prop(props, key, flags, fallback) {
307315
};
308316

309317
if (prop_value === undefined && fallback !== undefined) {
310-
if (setter && runes) {
318+
if (setter && runes && !is_entry_props) {
311319
e.props_invalid_value(key);
312320
}
313321

packages/svelte/src/internal/client/validate.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import { dev_current_component_function, untrack } from './runtime.js';
1+
import { dev_current_component_function } from './runtime.js';
22
import { get_descriptor, is_array } from '../shared/utils.js';
33
import * as e from './errors.js';
44
import { FILENAME } from '../../constants.js';
55
import { render_effect } from './reactivity/effects.js';
66
import * as w from './warnings.js';
77
import { capture_store_binding } from './reactivity/store.js';
88

9-
/** regex of all html void element names */
10-
const void_element_names =
11-
/^(?:area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/;
12-
13-
/** @param {string} tag */
14-
function is_void(tag) {
15-
return void_element_names.test(tag) || tag.toLowerCase() === '!doctype';
16-
}
17-
189
/**
1910
* @param {() => any} collection
2011
* @param {(item: any, index: number) => string} key_fn

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @import { ComponentConstructorOptions, ComponentType, SvelteComponent, Component } from 'svelte' */
2-
import { DIRTY, MAYBE_DIRTY } from '../internal/client/constants.js';
2+
import { DIRTY, LEGACY_PROPS, MAYBE_DIRTY } from '../internal/client/constants.js';
33
import { user_pre_effect } from '../internal/client/reactivity/effects.js';
44
import { mutable_source, set } from '../internal/client/reactivity/sources.js';
55
import { hydrate, mount, unmount } from '../internal/client/render.js';
@@ -89,7 +89,7 @@ class Svelte4Component {
8989
};
9090

9191
// Replicate coarse-grained props through a proxy that has a version source for
92-
// each property, which is increment on updates to the property itself. Do not
92+
// each property, which is incremented on updates to the property itself. Do not
9393
// use our $state proxy because that one has fine-grained reactivity.
9494
const props = new Proxy(
9595
{ ...(options.props || {}), $$events: {} },
@@ -98,26 +98,15 @@ class Svelte4Component {
9898
return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
9999
},
100100
has(target, prop) {
101+
// Necessary to not throw "invalid binding" validation errors on the component side
102+
if (prop === LEGACY_PROPS) return true;
103+
101104
get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
102105
return Reflect.has(target, prop);
103106
},
104107
set(target, prop, value) {
105108
set(sources.get(prop) ?? add_source(prop, value), value);
106109
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-
};
121110
}
122111
}
123112
);

0 commit comments

Comments
 (0)