fix: prevent memory leaking signals in legacy mode

pull/16145/head
7nik 3 months ago
parent 91272d702b
commit 1fdf11f25f

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: prevent memory leaking signals in legacy mode

@ -58,8 +58,8 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
/** @type {Effect | null} */ /** @type {Effect | null} */
var catch_effect; var catch_effect;
var input_source = (runes ? source : mutable_source)(/** @type {V} */ (undefined)); var input_source = runes ? source(/** @type {V} */ (undefined)) : mutable_source(/** @type {V} */ (undefined), false, false);
var error_source = (runes ? source : mutable_source)(undefined); var error_source = runes ? source(/** @type {V} */ (undefined)) : mutable_source(/** @type {V} */ (undefined), false, false);
var resolved = false; var resolved = false;
/** /**

@ -521,7 +521,7 @@ function create_item(
var reactive = (flags & EACH_ITEM_REACTIVE) !== 0; var reactive = (flags & EACH_ITEM_REACTIVE) !== 0;
var mutable = (flags & EACH_ITEM_IMMUTABLE) === 0; var mutable = (flags & EACH_ITEM_IMMUTABLE) === 0;
var v = reactive ? (mutable ? mutable_source(value) : source(value)) : value; var v = reactive ? (mutable ? mutable_source(value, false, false) : source(value)) : value;
var i = (flags & EACH_INDEX_REACTIVE) === 0 ? index : source(index); var i = (flags & EACH_INDEX_REACTIVE) === 0 ? index : source(index);
if (DEV && reactive) { if (DEV && reactive) {

@ -93,7 +93,7 @@ export function state(v, stack) {
* @returns {Source<V>} * @returns {Source<V>}
*/ */
/*#__NO_SIDE_EFFECTS__*/ /*#__NO_SIDE_EFFECTS__*/
export function mutable_source(initial_value, immutable = false) { export function mutable_source(initial_value, immutable = false, trackable = true) {
const s = source(initial_value); const s = source(initial_value);
if (!immutable) { if (!immutable) {
s.equals = safe_equals; s.equals = safe_equals;
@ -101,7 +101,7 @@ export function mutable_source(initial_value, immutable = false) {
// bind the signal to the component context, in case we need to // bind the signal to the component context, in case we need to
// track updates to trigger beforeUpdate/afterUpdate callbacks // track updates to trigger beforeUpdate/afterUpdate callbacks
if (legacy_mode_flag && component_context !== null && component_context.l !== null) { if (trackable && legacy_mode_flag && component_context !== null && component_context.l !== null) {
(component_context.l.s ??= []).push(s); (component_context.l.s ??= []).push(s);
} }

@ -82,7 +82,7 @@ class Svelte4Component {
* @param {unknown} value * @param {unknown} value
*/ */
var add_source = (key, value) => { var add_source = (key, value) => {
var s = mutable_source(value); var s = mutable_source(value, false, false);
sources.set(key, s); sources.set(key, s);
return s; return s;
}; };

Loading…
Cancel
Save