Skip to content

remove PROXY_REMOVE_PATH #16126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { get_rune } from '../../../scope.js';
import { get_prop_source, is_prop_source, is_state_source, should_proxy } from '../utils.js';
import { is_hoisted_function } from '../../utils.js';
import { get_value } from './shared/declarations.js';
import { PROXY_REMOVE_PATH } from '#client/constants';

/**
* @param {VariableDeclaration} node
Expand Down Expand Up @@ -90,12 +89,7 @@ export function VariableDeclaration(node, context) {
binding.kind === 'bindable_prop' &&
should_proxy(initial, context.state.scope)
) {
initial = b.call(
'$.proxy',
initial,
dev ? b.literal(id.name) : undefined,
dev ? b.literal(PROXY_REMOVE_PATH) : undefined
);
initial = b.call('$.proxy', initial, dev && b.literal(id.name));
}

if (is_prop_source(binding, context.state)) {
Expand Down Expand Up @@ -136,20 +130,19 @@ export function VariableDeclaration(node, context) {
);
const is_state = is_state_source(binding, context.state.analysis);
const is_proxy = should_proxy(value, context.state.scope);

if (rune === '$state' && is_proxy) {
value = b.call(
'$.proxy',
value,
dev ? b.literal(id.name) : undefined,
dev ? b.literal(PROXY_REMOVE_PATH) : undefined
);
value = b.call('$.proxy', value, dev && b.literal(id.name));
}

if (is_state) {
value = b.call('$.state', value);

if (dev) {
value = b.call('$.tag', value, b.literal(id.name));
}
}
if (dev && is_state) {
value = b.call('$.tag', value, b.literal(id.name));
}

return value;
};

Expand Down
8 changes: 0 additions & 8 deletions packages/svelte/src/internal/client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ export const HEAD_EFFECT = 1 << 19;
export const EFFECT_HAS_DERIVED = 1 << 20;
export const EFFECT_IS_UPDATING = 1 << 21;

// `$inspect.trace` proxy path flags
/** Keep path the same */
export const PROXY_PRESERVE_PATH = 1 << 1;
/** Change proxy path to new "owner" */
export const PROXY_CHANGE_PATH = 1 << 2;
/** "Unown" proxy, so its path becomes `[$state proxy]` */
export const PROXY_REMOVE_PATH = 1 << 3;

export const STATE_SYMBOL = Symbol('$state');
export const LEGACY_PROPS = Symbol('legacy props');
export const LOADING_ATTR_SYMBOL = Symbol('');
Expand Down
21 changes: 7 additions & 14 deletions packages/svelte/src/internal/client/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import {
object_prototype
} from '../shared/utils.js';
import { state as source, set } from './reactivity/sources.js';
import {
PROXY_CHANGE_PATH,
PROXY_PATH_SYMBOL,
PROXY_PRESERVE_PATH,
PROXY_REMOVE_PATH,
STATE_SYMBOL
} from '#client/constants';
import { PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
import { UNINITIALIZED } from '../../constants.js';
import * as e from './errors.js';
import { get_stack, tag } from './dev/tracing.js';
Expand All @@ -25,21 +19,20 @@ import { tracing_mode_flag } from '../flags/index.js';
* @template T
* @param {T} value
* @param {string} [path]
* @param {number} [path_preservation]
* @param {boolean} change_path
* @returns {T}
*/
export function proxy(value, path, path_preservation = PROXY_PRESERVE_PATH) {
export function proxy(value, path, change_path = false) {
// if `DEV`, change the proxy `path` since we don't know if its still "owned" by its original source
if (
DEV &&
(path_preservation & PROXY_PRESERVE_PATH) === 0 &&
change_path &&
typeof value === 'object' &&
value !== null &&
STATE_SYMBOL in value &&
PROXY_PATH_SYMBOL in value
) {
value[PROXY_PATH_SYMBOL] =
(path_preservation & PROXY_CHANGE_PATH) === 0 ? '[$state proxy]' : path;
value[PROXY_PATH_SYMBOL] = path;
}
// if non-proxyable, or is already a proxy, return `value`
if (typeof value !== 'object' || value === null || STATE_SYMBOL in value) {
Expand Down Expand Up @@ -272,15 +265,15 @@ export function proxy(value, path, path_preservation = PROXY_PRESERVE_PATH) {
s = DEV ? tag(s, to_trace_name(prop)) : s;
set(
s,
with_parent(() => proxy(value, to_trace_name(prop), PROXY_CHANGE_PATH))
with_parent(() => proxy(value, to_trace_name(prop), true))
);
sources.set(prop, s);
}
} else {
has = s.v !== UNINITIALIZED;
set(
s,
with_parent(() => proxy(value, to_trace_name(prop), PROXY_CHANGE_PATH))
with_parent(() => proxy(value, to_trace_name(prop), true))
);
}

Expand Down
7 changes: 2 additions & 5 deletions packages/svelte/src/internal/client/reactivity/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import {
UNOWNED,
MAYBE_DIRTY,
BLOCK_EFFECT,
ROOT_EFFECT,
PROXY_REMOVE_PATH
ROOT_EFFECT
} from '#client/constants';
import * as e from '../errors.js';
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
Expand Down Expand Up @@ -140,9 +139,7 @@ export function set(source, value, should_proxy = false) {
e.state_unsafe_mutation();
}

let new_value = should_proxy
? proxy(value, DEV ? source.trace_name : undefined, DEV ? PROXY_REMOVE_PATH : undefined)
: value;
let new_value = should_proxy ? proxy(value, DEV ? source.trace_name : undefined) : value;

return internal_set(source, new_value);
}
Expand Down