Skip to content

Commit 85e7439

Browse files
committed
make it unnecessary to hand onto current_sources past the initial update
1 parent 38e6943 commit 85e7439

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/** @import { Source } from '#client' */
22
import { DEV } from 'esm-env';
3-
import { get, active_effect, current_sources, set_current_sources } from './runtime.js';
3+
import {
4+
get,
5+
active_effect,
6+
update_version,
7+
active_reaction,
8+
set_update_version,
9+
set_active_reaction
10+
} from './runtime.js';
411
import {
512
array_prototype,
613
get_descriptor,
@@ -41,21 +48,31 @@ export function proxy(value) {
4148
var version = source(0);
4249

4350
var stack = DEV && tracing_mode_flag ? get_stack('CreatedAt') : null;
44-
var parent_sources = current_sources;
51+
var parent_version = update_version;
4552

4653
/**
4754
* Executes the proxy in the context of the reaction it was originally created in, if any
4855
* @template T
4956
* @param {() => T} fn
5057
*/
5158
var with_parent = (fn) => {
52-
var previous_sources = current_sources;
53-
set_current_sources(parent_sources);
59+
if (update_version === parent_version) {
60+
return fn();
61+
}
62+
63+
// child source is being created after the initial proxy —
64+
// prevent it from being associated with the current reaction
65+
var reaction = active_reaction;
66+
var version = update_version;
67+
68+
set_active_reaction(null);
69+
set_update_version(parent_version);
5470

55-
/** @type {T} */
5671
var result = fn();
5772

58-
set_current_sources(previous_sources);
73+
set_active_reaction(reaction);
74+
set_update_version(version);
75+
5976
return result;
6077
};
6178

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ export function set_active_effect(effect) {
9292
*/
9393
export let current_sources = null;
9494

95-
/**
96-
* @param {null | Source[]} value
97-
*/
98-
export function set_current_sources(value) {
99-
current_sources = value;
100-
}
101-
10295
/** @param {Value} value */
10396
export function push_reaction_value(value) {
10497
if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
@@ -143,6 +136,11 @@ let read_version = 0;
143136

144137
export let update_version = read_version;
145138

139+
/** @param {number} value */
140+
export function set_update_version(value) {
141+
update_version = value;
142+
}
143+
146144
// If we are working with a get() chain that has no active container,
147145
// to prevent memory leaks, we skip adding the reaction.
148146
export let skip_reaction = false;

0 commit comments

Comments
 (0)