From 927e5baff2d760fc33df43c0b9fd54ee1979ff71 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 12 Oct 2026 22:15:32 -0400 Subject: [PATCH] chore: remove first_batch?.next checks for reads outside reactivity Neither the check in internal_set nor the one in update_derived is needed for any test. --- .../svelte/src/internal/client/reactivity/deriveds.js | 10 +++------- .../svelte/src/internal/client/reactivity/sources.js | 9 ++------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/deriveds.js b/packages/svelte/src/internal/client/reactivity/deriveds.js index 9b2b791a17..85755ca55f 100644 --- a/packages/svelte/src/internal/client/reactivity/deriveds.js +++ b/packages/svelte/src/internal/client/reactivity/deriveds.js @@ -44,7 +44,7 @@ import { get_error } from '../../shared/dev.js'; import { async_mode_flag, tracing_mode_flag } from '../../flags/index.js'; import { component_context } from '../context.js'; import { UNINITIALIZED } from '../../../constants.js'; -import { batch_values, current_batch, first_batch, previous_batch } from './batch.js'; +import { batch_values, current_batch, previous_batch } from './batch.js'; import { increment_pending, unset_context } from './async.js'; import { deferred, includes, noop } from '../../shared/utils.js'; import { set_signal_status, update_derived_status } from './status.js'; @@ -445,15 +445,11 @@ export function update_derived(derived) { // During time travelling, keep stale results batch-local. A result computed // from the latest inputs can be marked globally clean, even if it is unchanged // and its write version therefore remains below its dependencies' versions. - if ( - batch_values !== null || - // "read outside of reactivity", e.g. in an event handler - (!current_batch && first_batch?.next) - ) { + if (batch_values !== null) { // only cache the value if we're in a tracking context, otherwise we won't // clear the cache in `mark_reactions` when dependencies are updated if (effect_tracking() || current_batch?.is_fork) { - batch_values?.set(derived, value); + batch_values.set(derived, value); } var is_latest_value = value === derived.v && diff --git a/packages/svelte/src/internal/client/reactivity/sources.js b/packages/svelte/src/internal/client/reactivity/sources.js index 68d0e53e22..5dcdbcd065 100644 --- a/packages/svelte/src/internal/client/reactivity/sources.js +++ b/packages/svelte/src/internal/client/reactivity/sources.js @@ -36,8 +36,7 @@ import { batch_values, eager_block_effects, schedule_effect, - legacy_updates, - first_batch + legacy_updates } from './batch.js'; import { proxy } from '../proxy.js'; import { execute_derived } from './deriveds.js'; @@ -206,11 +205,7 @@ export function internal_set(source, value, updated_during_traversal = null) { // During time traveling we don't want to reset the status so that // traversal of the graph in the other batches still happens - if ( - batch_values === null && - // could also be "read outside of reactivity", e.g. in an event handler - !first_batch?.next - ) { + if (batch_values === null) { update_derived_status(derived); } }