Skip to content

Commit e862e5e

Browse files
committed
try suggestion
1 parent c745945 commit e862e5e

File tree

3 files changed

+15
-30
lines changed

3 files changed

+15
-30
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,18 @@ export function get_stack(label) {
179179
*/
180180
export function tag(source, label) {
181181
source.label = label;
182-
tag_proxy(source.v, label, source);
182+
tag_proxy(source.v, label);
183183

184184
return source;
185185
}
186186

187187
/**
188188
* @param {unknown} value
189189
* @param {string} label
190-
* @param {Value} source
191190
*/
192-
export function tag_proxy(value, label, source) {
191+
export function tag_proxy(value, label) {
193192
// @ts-expect-error
194-
value?.[PROXY_PATH_SYMBOL]?.(label, source);
193+
value?.[PROXY_PATH_SYMBOL]?.(label);
195194
return value;
196195
}
197196

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

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,9 @@ const regex_is_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
3434
/**
3535
* @template T
3636
* @param {T} value
37-
* @param {WeakSet<Source>} [owned_sources]
3837
* @returns {T}
3938
*/
40-
export function proxy(value, owned_sources) {
41-
if (DEV) {
42-
owned_sources ??= new WeakSet();
43-
}
39+
export function proxy(value) {
4440
// if non-proxyable, or is already a proxy, return `value`
4541
if (typeof value !== 'object' || value === null || STATE_SYMBOL in value) {
4642
return value;
@@ -97,16 +93,11 @@ export function proxy(value, owned_sources) {
9793

9894
/** Used in dev for $inspect.trace() */
9995
var path = '';
100-
101-
/**
102-
* @param {string} new_path
103-
* @param {Source} updater the source causing the path update
104-
*/
105-
function update_path(new_path, updater) {
106-
// there's a circular reference somewhere, don't update the path to avoid recursion
107-
if (owned_sources?.has(updater)) {
108-
return;
109-
}
96+
let updating = false;
97+
/** @param {string} new_path */
98+
function update_path(new_path) {
99+
if (updating) return;
100+
updating = true;
110101
path = new_path;
111102

112103
tag(version, `${path} version`);
@@ -115,6 +106,7 @@ export function proxy(value, owned_sources) {
115106
for (const [prop, source] of sources) {
116107
tag(source, get_label(path, prop));
117108
}
109+
updating = false;
118110
}
119111

120112
return new Proxy(/** @type {any} */ (value), {
@@ -138,7 +130,6 @@ export function proxy(value, owned_sources) {
138130
sources.set(prop, s);
139131
if (DEV && typeof prop === 'string') {
140132
tag(s, get_label(path, prop));
141-
owned_sources?.add(s);
142133
}
143134
return s;
144135
});
@@ -160,7 +151,6 @@ export function proxy(value, owned_sources) {
160151

161152
if (DEV) {
162153
tag(s, get_label(path, prop));
163-
owned_sources?.add(s);
164154
}
165155
}
166156
} else {
@@ -186,12 +176,11 @@ export function proxy(value, owned_sources) {
186176
// create a source, but only if it's an own property and not a prototype property
187177
if (s === undefined && (!exists || get_descriptor(target, prop)?.writable)) {
188178
s = with_parent(() => {
189-
var p = proxy(exists ? target[prop] : UNINITIALIZED, DEV ? owned_sources : undefined);
179+
var p = proxy(exists ? target[prop] : UNINITIALIZED);
190180
var s = source(p, stack);
191181

192182
if (DEV) {
193183
tag(s, get_label(path, prop));
194-
owned_sources?.add(s);
195184
}
196185

197186
return s;
@@ -245,12 +234,11 @@ export function proxy(value, owned_sources) {
245234
) {
246235
if (s === undefined) {
247236
s = with_parent(() => {
248-
var p = has ? proxy(target[prop], DEV ? owned_sources : undefined) : UNINITIALIZED;
237+
var p = has ? proxy(target[prop]) : UNINITIALIZED;
249238
var s = source(p, stack);
250239

251240
if (DEV) {
252241
tag(s, get_label(path, prop));
253-
owned_sources?.add(s);
254242
}
255243

256244
return s;
@@ -287,7 +275,6 @@ export function proxy(value, owned_sources) {
287275

288276
if (DEV) {
289277
tag(other_s, get_label(path, i));
290-
owned_sources?.add(other_s);
291278
}
292279
}
293280
}
@@ -300,19 +287,18 @@ export function proxy(value, owned_sources) {
300287
if (s === undefined) {
301288
if (!has || get_descriptor(target, prop)?.writable) {
302289
s = with_parent(() => source(undefined, stack));
303-
set(s, proxy(value, DEV ? owned_sources : undefined));
290+
set(s, proxy(value));
304291

305292
sources.set(prop, s);
306293

307294
if (DEV) {
308295
tag(s, get_label(path, prop));
309-
owned_sources?.add(s);
310296
}
311297
}
312298
} else {
313299
has = s.v !== UNINITIALIZED;
314300

315-
var p = with_parent(() => proxy(value, DEV ? owned_sources : undefined));
301+
var p = with_parent(() => proxy(value));
316302
set(s, p);
317303
}
318304

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function set(source, value, should_proxy = false) {
156156
let new_value = should_proxy ? proxy(value) : value;
157157

158158
if (DEV) {
159-
tag_proxy(new_value, /** @type {string} */ (source.label), source);
159+
tag_proxy(new_value, /** @type {string} */ (source.label));
160160
}
161161

162162
return internal_set(source, new_value);

0 commit comments

Comments
 (0)