Skip to content

Commit f4e98bf

Browse files
Revert "fix: ensure untrack correctly retains the active reaction (#15065)"
This reverts commit 2ad5195.
1 parent c75f1f5 commit f4e98bf

File tree

4 files changed

+9
-56
lines changed

4 files changed

+9
-56
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {
1616
set_is_flushing_effect,
1717
set_signal_status,
1818
untrack,
19-
skip_reaction,
20-
untracking
19+
skip_reaction
2120
} from '../runtime.js';
2221
import {
2322
DIRTY,
@@ -44,7 +43,8 @@ import * as e from '../errors.js';
4443
import { DEV } from 'esm-env';
4544
import { define_property } from '../../shared/utils.js';
4645
import { get_next_sibling } from '../dom/operations.js';
47-
import { derived, destroy_derived } from './deriveds.js';
46+
import { derived, derived_safe_equal, destroy_derived } from './deriveds.js';
47+
import { legacy_mode_flag } from '../../flags/index.js';
4848

4949
/**
5050
* @param {'$effect' | '$effect.pre' | '$inspect'} rune
@@ -166,7 +166,7 @@ function create_effect(type, fn, sync, push = true) {
166166
* @returns {boolean}
167167
*/
168168
export function effect_tracking() {
169-
if (active_reaction === null || untracking) {
169+
if (active_reaction === null) {
170170
return false;
171171
}
172172

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import {
1717
set_derived_sources,
1818
check_dirtiness,
1919
set_is_flushing_effect,
20-
is_flushing_effect,
21-
untracking
20+
is_flushing_effect
2221
} from '../runtime.js';
2322
import { equals, safe_equals } from './equality.js';
2423
import {
@@ -149,7 +148,6 @@ export function mutate(source, value) {
149148
export function set(source, value) {
150149
if (
151150
active_reaction !== null &&
152-
!untracking &&
153151
is_runes() &&
154152
(active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0 &&
155153
// If the source was created locally within the current derived, then

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ let dev_effect_stack = [];
7878
/** @type {null | Reaction} */
7979
export let active_reaction = null;
8080

81-
export let untracking = false;
82-
8381
/** @param {null | Reaction} reaction */
8482
export function set_active_reaction(reaction) {
8583
active_reaction = reaction;
@@ -425,7 +423,6 @@ export function update_reaction(reaction) {
425423
var previous_skip_reaction = skip_reaction;
426424
var prev_derived_sources = derived_sources;
427425
var previous_component_context = component_context;
428-
var previous_untracking = untracking;
429426
var flags = reaction.f;
430427

431428
new_deps = /** @type {null | Value[]} */ (null);
@@ -435,7 +432,6 @@ export function update_reaction(reaction) {
435432
skip_reaction = !is_flushing_effect && (flags & UNOWNED) !== 0;
436433
derived_sources = null;
437434
component_context = reaction.ctx;
438-
untracking = false;
439435
read_version++;
440436

441437
try {
@@ -499,7 +495,6 @@ export function update_reaction(reaction) {
499495
skip_reaction = previous_skip_reaction;
500496
derived_sources = prev_derived_sources;
501497
component_context = previous_component_context;
502-
untracking = previous_untracking;
503498
}
504499
}
505500

@@ -939,7 +934,7 @@ export function get(signal) {
939934
}
940935

941936
// Register the dependency on the current reaction signal.
942-
if (active_reaction !== null && !untracking) {
937+
if (active_reaction !== null) {
943938
if (derived_sources !== null && derived_sources.includes(signal)) {
944939
e.state_unsafe_local_read();
945940
}
@@ -1090,12 +1085,12 @@ export function invalidate_inner_signals(fn) {
10901085
* @returns {T}
10911086
*/
10921087
export function untrack(fn) {
1093-
var previous_untracking = untracking;
1088+
const previous_reaction = active_reaction;
10941089
try {
1095-
untracking = true;
1090+
active_reaction = null;
10961091
return fn();
10971092
} finally {
1098-
untracking = previous_untracking;
1093+
active_reaction = previous_reaction;
10991094
}
11001095
}
11011096

packages/svelte/tests/signals/test.ts

-40
Original file line numberDiff line numberDiff line change
@@ -803,46 +803,6 @@ describe('signals', () => {
803803
};
804804
});
805805

806-
test('deriveds containing effects work correctly when used with untrack', () => {
807-
return () => {
808-
let a = render_effect(() => {});
809-
let b = state(0);
810-
let c;
811-
let effects = [];
812-
813-
const destroy = effect_root(() => {
814-
a = render_effect(() => {
815-
c = derived(() => {
816-
$.untrack(() => {
817-
effects.push(
818-
effect(() => {
819-
$.get(b);
820-
})
821-
);
822-
});
823-
$.get(b);
824-
});
825-
$.get(c);
826-
});
827-
});
828-
829-
assert.deepEqual(c!.children?.length, 1);
830-
assert.deepEqual(a.first, a.last);
831-
832-
set(b, 1);
833-
834-
flushSync();
835-
836-
assert.deepEqual(c!.children?.length, 1);
837-
assert.deepEqual(a.first, a.last);
838-
839-
destroy();
840-
841-
assert.deepEqual(a.deriveds, null);
842-
assert.deepEqual(a.first, null);
843-
};
844-
});
845-
846806
test('bigint states update correctly', () => {
847807
return () => {
848808
const count = state(0n);

0 commit comments

Comments
 (0)