pull/15137/head
Dominic Gannaway 2 years ago
parent f6a489e172
commit 293bdfd721

@ -414,7 +414,13 @@ export function update_reaction(reaction) {
skipped_deps = 0;
untracked_writes = null;
active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
skip_reaction = !is_flushing_effect && (flags & UNOWNED) !== 0;
// prettier-ignore
skip_reaction =
(flags & UNOWNED) !== 0 &&
(!is_flushing_effect ||
(/** @type {Derived} */ (reaction).parent !== null &&
(/** @type {Derived} */ (reaction).parent.f & DERIVED) !== 0));
derived_sources = null;
set_component_context(reaction.ctx);
untracking = false;
@ -946,14 +952,14 @@ export function get(signal) {
var parent = derived.parent;
if (parent !== null) {
// Attach the derived to the nearest parent effect or derived
if ((parent.f & DERIVED) !== 0) {
var parent_derived = /** @type {Derived} */ (parent);
if (!parent_derived.children?.includes(derived)) {
(parent_derived.children ??= []).push(derived);
}
// If the derived is owned by another derived then mark it as unowned
// as the derived value might have been shared and thus we cannot determine
// a true
if ((parent.f & DERIVED) !== 0 && (parent.f & UNOWNED) === 0) {
debugger;
derived.f ^= UNOWNED;
} else {
// Otherwise we can attach the derieved to the parent effect
var parent_effect = /** @type {Effect} */ (parent);
if (!parent_effect.deriveds?.includes(derived)) {

@ -538,6 +538,64 @@ describe('signals', () => {
};
});
test('mixed nested deriveds correctly cleanup when no longer connected to graph #1', () => {
let a: Derived<unknown>;
let b: Derived<unknown>;
let s = state(0);
const destroy = effect_root(() => {
render_effect(() => {
a = derived(() => {
b = derived(() => {
$.get(s);
});
$.untrack(() => {
$.get(b);
});
$.get(s);
});
$.get(a);
});
});
return () => {
flushSync();
assert.equal(a?.deps?.length, 1);
assert.equal(s?.reactions?.length, 1);
destroy();
assert.equal(s?.reactions, null);
};
});
test('mixed nested deriveds correctly cleanup when no longer connected to graph #2', () => {
let a: Derived<unknown>;
let b: Derived<unknown>;
let s = state(0);
const destroy = effect_root(() => {
render_effect(() => {
a = derived(() => {
b = derived(() => {
$.get(s);
});
effect_root(() => {
$.get(b);
});
$.get(s);
});
$.get(a);
});
});
return () => {
flushSync();
assert.equal(a?.deps?.length, 1);
assert.equal(s?.reactions?.length, 1);
destroy();
assert.equal(s?.reactions, null);
};
});
test('deriveds update upon reconnection #1', () => {
let a = state(false);
let b = state(false);

Loading…
Cancel
Save