From b2439213535a7a12a48a4c15b93977373950b71a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 24 Aug 2024 11:45:06 -0400 Subject: [PATCH] tweak --- packages/svelte/src/internal/client/proxy.js | 4 ++-- .../src/internal/client/reactivity/sources.js | 16 +++++++++------- .../src/internal/client/reactivity/store.js | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/svelte/src/internal/client/proxy.js b/packages/svelte/src/internal/client/proxy.js index 9c3e6441c2..812f3d64a3 100644 --- a/packages/svelte/src/internal/client/proxy.js +++ b/packages/svelte/src/internal/client/proxy.js @@ -118,7 +118,7 @@ export function proxy(value, parent = null, prev) { // create a source, but only if it's an own property and not a prototype property if (s === undefined && (!exists || get_descriptor(target, prop)?.writable)) { - s = source(proxy(exists ? target[prop] : UNINITIALIZED, metadata), true); + s = source(proxy(exists ? target[prop] : UNINITIALIZED, metadata), null); sources.set(prop, s); } @@ -170,7 +170,7 @@ export function proxy(value, parent = null, prev) { (current_effect !== null && (!has || get_descriptor(target, prop)?.writable)) ) { if (s === undefined) { - s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED, true); + s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED, null); sources.set(prop, s); } diff --git a/packages/svelte/src/internal/client/reactivity/sources.js b/packages/svelte/src/internal/client/reactivity/sources.js index d276e727b6..4b3750ac99 100644 --- a/packages/svelte/src/internal/client/reactivity/sources.js +++ b/packages/svelte/src/internal/client/reactivity/sources.js @@ -1,4 +1,4 @@ -/** @import { Derived, Effect, Source, Value } from '#client' */ +/** @import { Derived, Effect, Reaction, Source, Value } from '#client' */ import { DEV } from 'esm-env'; import { current_component_context, @@ -34,11 +34,11 @@ let inspect_effects = new Set(); /** * @template V * @param {V} v - * @param {boolean} [skip_derived_source] + * @param {Reaction | null} [owner] * @returns {Source} */ /*#__NO_SIDE_EFFECTS__*/ -export function source(v, skip_derived_source = false) { +export function source(v, owner = current_reaction) { var source = { f: 0, // TODO ideally we could skip this altogether, but it causes type errors v, @@ -46,25 +46,27 @@ export function source(v, skip_derived_source = false) { equals, version: 0 }; - if (!skip_derived_source && current_reaction !== null && (current_reaction.f & DERIVED) !== 0) { + + if (owner !== null && (owner.f & DERIVED) !== 0) { if (derived_sources === null) { set_derived_sources([source]); } else { derived_sources.push(source); } } + return source; } /** * @template V * @param {V} initial_value - * @param {boolean} [skip_derived_source] + * @param {Reaction | null} [owner] * @returns {Source} */ /*#__NO_SIDE_EFFECTS__*/ -export function mutable_source(initial_value, skip_derived_source) { - const s = source(initial_value, skip_derived_source); +export function mutable_source(initial_value, owner) { + const s = source(initial_value, owner); s.equals = safe_equals; // bind the signal to the component context, in case we need to diff --git a/packages/svelte/src/internal/client/reactivity/store.js b/packages/svelte/src/internal/client/reactivity/store.js index 018cac6fdd..d95e42b0db 100644 --- a/packages/svelte/src/internal/client/reactivity/store.js +++ b/packages/svelte/src/internal/client/reactivity/store.js @@ -19,7 +19,7 @@ import { mutable_source, set } from './sources.js'; export function store_get(store, store_name, stores) { const entry = (stores[store_name] ??= { store: null, - source: mutable_source(undefined, true), + source: mutable_source(undefined, null), unsubscribe: noop });