diff --git a/packages/svelte/src/internal/client/reactivity/sources.js b/packages/svelte/src/internal/client/reactivity/sources.js index c35b0a84e0..44eb2b1ad8 100644 --- a/packages/svelte/src/internal/client/reactivity/sources.js +++ b/packages/svelte/src/internal/client/reactivity/sources.js @@ -8,7 +8,6 @@ import { current_untracking, flushSync, get, - ignore_mutation_validation, is_batching_effect, is_runes, mark_reactions, @@ -19,7 +18,7 @@ import { untrack } from '../runtime.js'; import { equals, safe_equals } from './equality.js'; -import { CLEAN, DERIVED, DIRTY, MANAGED } from '../constants.js'; +import { CLEAN, DERIVED, DIRTY, MANAGED, UNINITIALIZED } from '../constants.js'; /** * @template V @@ -93,9 +92,11 @@ export function mutate(source, value) { * @returns {V} */ export function set(signal, value) { + var initialized = signal.v !== UNINITIALIZED; + if ( !current_untracking && - !ignore_mutation_validation && + initialized && current_reaction !== null && is_runes() && (current_reaction.f & DERIVED) !== 0 @@ -124,11 +125,10 @@ export function set(signal, value) { // // $effect(() => x++) // - // We additionally want to skip this logic for when ignore_mutation_validation is - // true, as stores write to source signal on initialisation. + // We additionally want to skip this logic when initialising store sources if ( is_runes() && - !ignore_mutation_validation && + initialized && current_effect !== null && (current_effect.f & CLEAN) !== 0 && (current_effect.f & MANAGED) === 0 diff --git a/packages/svelte/src/internal/client/reactivity/store.js b/packages/svelte/src/internal/client/reactivity/store.js index 7ea57428da..1d07f59288 100644 --- a/packages/svelte/src/internal/client/reactivity/store.js +++ b/packages/svelte/src/internal/client/reactivity/store.js @@ -1,7 +1,7 @@ import { subscribe_to_store } from '../../../store/utils.js'; import { noop } from '../../common.js'; import { UNINITIALIZED } from '../constants.js'; -import { get, set_ignore_mutation_validation, untrack } from '../runtime.js'; +import { get, untrack } from '../runtime.js'; import { user_effect } from './effects.js'; import { mutable_source, set } from './sources.js'; @@ -74,13 +74,7 @@ function connect_store_to_signal(store, source) { return noop; } - /** @param {V} v */ - const run = (v) => { - set_ignore_mutation_validation(true); - set(source, v); - set_ignore_mutation_validation(false); - }; - return subscribe_to_store(store, run); + return subscribe_to_store(store, (v) => set(source, v)); } /** diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 4c45dd0f22..2620cddddd 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -84,12 +84,6 @@ export function set_last_inspected_signal(signal) { /** If `true`, `get`ting the signal should not register it as a dependency */ export let current_untracking = false; -/** Exists to opt out of the mutation validation for stores which may be set for the first time during a derivation */ -export let ignore_mutation_validation = false; -/** @param {boolean} value */ -export function set_ignore_mutation_validation(value) { - ignore_mutation_validation = value; -} // If we are working with a get() chain that has no active container, // to prevent memory leaks, we skip adding the reaction.