Skip to content

Commit 8fda58a

Browse files
committed
fix: use strategy suggested by actually competent person aka @dummdidumm
1 parent 7e95260 commit 8fda58a

File tree

5 files changed

+12
-62
lines changed

5 files changed

+12
-62
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ export function validate_mutation(node, context, expression) {
348348
b.literal(binding.prop_alias),
349349
b.array(path),
350350
expression,
351-
binding.prop_alias != null && b.id(binding.prop_alias),
352351
loc && b.literal(loc.line),
353352
loc && b.literal(loc.column)
354353
);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ export const EFFECT_HAS_DERIVED = 1 << 20;
2323
export const EFFECT_IS_UPDATING = 1 << 21;
2424

2525
export const STATE_SYMBOL = Symbol('$state');
26-
export const BINDABLE_FALLBACK_SYMBOL = Symbol('bindable fallback');
2726
export const LEGACY_PROPS = Symbol('legacy props');
2827
export const LOADING_ATTR_SYMBOL = Symbol('');

packages/svelte/src/internal/client/dev/ownership.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @typedef {{ file: string, line: number, column: number }} Location */
22

33
import { get_descriptor } from '../../shared/utils.js';
4-
import { BINDABLE_FALLBACK_SYMBOL, LEGACY_PROPS, STATE_SYMBOL } from '../constants.js';
4+
import { LEGACY_PROPS, STATE_SYMBOL } from '../constants.js';
55
import { FILENAME } from '../../../constants.js';
66
import { component_context } from '../context.js';
77
import * as w from '../warnings.js';
@@ -22,13 +22,12 @@ export function create_ownership_validator(props) {
2222
* @param {string} prop
2323
* @param {any[]} path
2424
* @param {any} result
25-
* @param {any} prop_value
2625
* @param {number} line
2726
* @param {number} column
2827
*/
29-
mutation: (prop, path, result, prop_value, line, column) => {
28+
mutation: (prop, path, result, line, column) => {
3029
const name = path[0];
31-
if (is_bound(props, name) || !parent || prop_value()?.[BINDABLE_FALLBACK_SYMBOL]) {
30+
if (is_bound(props, name) || !parent) {
3231
return result;
3332
}
3433

@@ -53,14 +52,7 @@ export function create_ownership_validator(props) {
5352
* @param {() => any} value
5453
*/
5554
binding: (key, child_component, value) => {
56-
var val;
57-
if (
58-
!is_bound(props, key) &&
59-
parent &&
60-
// we do this trick to prevent calling the value function twice
61-
(val = value())?.[STATE_SYMBOL] &&
62-
!val[BINDABLE_FALLBACK_SYMBOL]
63-
) {
55+
if (!is_bound(props, key) && parent && value()?.[STATE_SYMBOL]) {
6456
w.ownership_invalid_binding(
6557
component[FILENAME],
6658
key,
@@ -80,5 +72,9 @@ function is_bound(props, prop_name) {
8072
// Can be the case when someone does `mount(Component, props)` with `let props = $state({...})`
8173
// or `createClassComponent(Component, props)`
8274
const is_entry_props = STATE_SYMBOL in props || LEGACY_PROPS in props;
83-
return !!get_descriptor(props, prop_name)?.set || (is_entry_props && prop_name in props);
75+
return (
76+
!!get_descriptor(props, prop_name)?.set ||
77+
(is_entry_props && prop_name in props) ||
78+
!(prop_name in props)
79+
);
8480
}

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
object_prototype
1010
} from '../shared/utils.js';
1111
import { state as source, set } from './reactivity/sources.js';
12-
import { BINDABLE_FALLBACK_SYMBOL, STATE_SYMBOL } from './constants.js';
12+
import { STATE_SYMBOL } from './constants.js';
1313
import { UNINITIALIZED } from '../../constants.js';
1414
import * as e from './errors.js';
1515
import { get_stack } from './dev/tracing.js';
@@ -63,12 +63,6 @@ export function proxy(value) {
6363

6464
return new Proxy(/** @type {any} */ (value), {
6565
defineProperty(_, prop, descriptor) {
66-
// we allow non enumerable/writable defines if the prop being set is our own symbol
67-
// this should be fine for the invariants since the user can't get a handle to the symbol
68-
if (DEV && prop === BINDABLE_FALLBACK_SYMBOL) {
69-
return Reflect.defineProperty(_, prop, descriptor);
70-
}
71-
7266
if (
7367
!('value' in descriptor) ||
7468
descriptor.configurable === false ||
@@ -129,9 +123,6 @@ export function proxy(value) {
129123
if (prop === STATE_SYMBOL) {
130124
return value;
131125
}
132-
if (DEV && prop === BINDABLE_FALLBACK_SYMBOL) {
133-
return Reflect.get(target, prop);
134-
}
135126

136127
var s = sources.get(prop);
137128
var exists = prop in target;
@@ -272,9 +263,7 @@ export function proxy(value) {
272263

273264
var own_keys = Reflect.ownKeys(target).filter((key) => {
274265
var source = sources.get(key);
275-
return (
276-
source === undefined || source.v !== UNINITIALIZED || key !== BINDABLE_FALLBACK_SYMBOL
277-
);
266+
return source === undefined || source.v !== UNINITIALIZED;
278267
});
279268

280269
for (var [key, source] of sources) {

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

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ import { derived, derived_safe_equal } from './deriveds.js';
1313
import { get, captured_signals, untrack } from '../runtime.js';
1414
import { safe_equals } from './equality.js';
1515
import * as e from '../errors.js';
16-
import {
17-
BINDABLE_FALLBACK_SYMBOL,
18-
LEGACY_DERIVED_PROP,
19-
LEGACY_PROPS,
20-
STATE_SYMBOL
21-
} from '../constants.js';
16+
import { LEGACY_DERIVED_PROP, LEGACY_PROPS, STATE_SYMBOL } from '../constants.js';
2217
import { proxy } from '../proxy.js';
2318
import { capture_store_binding } from './store.js';
2419
import { legacy_mode_flag } from '../../flags/index.js';
@@ -309,29 +304,6 @@ export function prop(props, key, flags, fallback) {
309304
if (setter) setter(prop_value);
310305
}
311306

312-
/**
313-
* @param {any} value
314-
*/
315-
function set_bindable_fallback(value) {
316-
if (DEV && !setter && fallback_used && value != null && typeof value === 'object') {
317-
// in dev we issue a warning if a bindable prop is passed with bindable
318-
// to a child if the prop doesn't have a setter but if it's a fallback
319-
// it's a false positive since the state it's actually created in this
320-
// component so we store the fact that this is a bindable fallback with
321-
// a symbol
322-
define_property(value, BINDABLE_FALLBACK_SYMBOL, {
323-
enumerable: false,
324-
// it needs to be configurable or the proxy will complain when we return true
325-
// for a non configurable property
326-
configurable: true,
327-
writable: false,
328-
value: true
329-
});
330-
}
331-
}
332-
333-
set_bindable_fallback(prop_value);
334-
335307
/** @type {() => V} */
336308
var getter;
337309
if (runes) {
@@ -427,11 +399,6 @@ export function prop(props, key, flags, fallback) {
427399
if (arguments.length > 0) {
428400
const new_value = mutation ? get(current_value) : runes && bindable ? proxy(value) : value;
429401

430-
// we only care to add the symbol if the original prop is reassigned
431-
if (runes && bindable && !mutation) {
432-
set_bindable_fallback(new_value);
433-
}
434-
435402
if (!current_value.equals(new_value)) {
436403
from_child = true;
437404
set(inner_current_value, new_value);

0 commit comments

Comments
 (0)