Skip to content

Commit 25d9aa1

Browse files
authored
chore: simplify signal capturing logic (#14281)
1 parent f5a7d49 commit 25d9aa1

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

packages/svelte/src/internal/client/reactivity/props.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { derived, derived_safe_equal } from './deriveds.js';
1313
import {
1414
active_effect,
1515
get,
16-
is_signals_recorded,
16+
captured_signals,
1717
set_active_effect,
1818
untrack,
1919
update
@@ -390,7 +390,7 @@ export function prop(props, key, flags, fallback) {
390390
return function (/** @type {any} */ value, /** @type {boolean} */ mutation) {
391391
// legacy nonsense — need to ensure the source is invalidated when necessary
392392
// also needed for when handling inspect logic so we can inspect the correct source signal
393-
if (is_signals_recorded) {
393+
if (captured_signals !== null) {
394394
// set this so that we don't reset to the parent value if `d`
395395
// is invalidated because of `invalidate_inner_signals` (rather
396396
// than because the parent or child value changed)

packages/svelte/src/internal/client/runtime.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ let current_version = 0;
128128
// to prevent memory leaks, we skip adding the reaction.
129129
export let skip_reaction = false;
130130
// Handle collecting all signals which are read during a specific time frame
131-
export let is_signals_recorded = false;
132-
let captured_signals = new Set();
131+
/** @type {Set<Value> | null} */
132+
export let captured_signals = null;
133133

134134
// Handling runtime component context
135135
/** @type {ComponentContext | null} */
@@ -732,7 +732,7 @@ export function get(signal) {
732732
return value;
733733
}
734734

735-
if (is_signals_recorded) {
735+
if (captured_signals !== null) {
736736
captured_signals.add(signal);
737737
}
738738

@@ -800,21 +800,18 @@ export function safe_get(signal) {
800800
* @param {() => any} fn
801801
*/
802802
export function invalidate_inner_signals(fn) {
803-
var previous_is_signals_recorded = is_signals_recorded;
804803
var previous_captured_signals = captured_signals;
805-
is_signals_recorded = true;
806804
captured_signals = new Set();
807805
var captured = captured_signals;
808806
var signal;
809807
try {
810808
untrack(fn);
811-
} finally {
812-
is_signals_recorded = previous_is_signals_recorded;
813-
if (is_signals_recorded) {
809+
if (previous_captured_signals !== null) {
814810
for (signal of captured_signals) {
815811
previous_captured_signals.add(signal);
816812
}
817813
}
814+
} finally {
818815
captured_signals = previous_captured_signals;
819816
}
820817
for (signal of captured) {

0 commit comments

Comments
 (0)