pull/12016/head
Dominic Gannaway 2 years ago
parent 32bfb21934
commit dd8af4634d

@ -6,9 +6,6 @@
"type": "module",
"license": "MIT",
"packageManager": "pnpm@9.2.0",
"engines": {
"pnpm": "^9.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sveltejs/svelte.git"

@ -454,13 +454,16 @@ function remove_reaction(signal, dependency) {
}
}
}
var flags = dependency.f;
// If the derived has no reactions, then we can disconnect it from the graph,
// allowing it to either reconnect in the future, or be GC'd by the VM.
if (reactions_length === 0 && (dependency.f & DERIVED) !== 0) {
set_signal_status(dependency, MAYBE_DIRTY);
if (reactions_length === 0 && (flags & DERIVED) !== 0) {
if ((flags & CLEAN) !== 0) {
set_signal_status(dependency, MAYBE_DIRTY);
}
// If we are working with a derived that is owned by an effect, then mark it as being
// disconnected.
if ((dependency.f & (UNOWNED | DISCONNECTED)) === 0) {
if ((flags & (UNOWNED | DISCONNECTED)) === 0) {
dependency.f ^= DISCONNECTED;
}
remove_reactions(/** @type {import('#client').Derived} **/ (dependency), 0);

@ -451,6 +451,7 @@ describe('signals', () => {
test('disconnected and reconnected deriveds work as intended', () => {
let a: Derived<unknown>;
let state = source(0);
let state_b = source(0);
let log: any[] = [];
let b = derived(() => {
log.push('b');
@ -458,6 +459,7 @@ describe('signals', () => {
});
let c = derived(() => {
log.push('c');
$.get(state_b);
return $.get(b);
});
let destroy: () => void;
@ -480,8 +482,14 @@ describe('signals', () => {
assert.deepEqual(log, ['a', 'c', 'b']);
log.length = 0;
destroy();
destroy = effect_root(() => {
render_effect(() => {
$.get(c);
set(state_b, 1);
});
});
destroy();
set(state, 1);
$.set_signal_status(c, DIRTY);
assert.equal($.get(c), 1);
assert.deepEqual(log, ['c', 'b']);
log.length = 0;

Loading…
Cancel
Save