fix: prevent memory leaking signals in legacy mode (#16145)

* fix: prevent memory leaking signals in legacy mode

* format

* fix

---------

Co-authored-by: 7nik <kifiranet@gmail.com>
pull/16157/head
7nik 3 months ago committed by GitHub
parent 92ea58bee6
commit 6636f748ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

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

@ -521,7 +521,7 @@ function create_item(
var reactive = (flags & EACH_ITEM_REACTIVE) !== 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);
if (DEV && reactive) {

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

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

Loading…
Cancel
Save