Skip to content

Commit b3084bc

Browse files
committed
fix: improve handled of unowned derived signals
1 parent 071d631 commit b3084bc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,21 @@ export function check_dirtiness(reaction) {
194194
// is also dirty.
195195
var version = dependency.version;
196196

197-
if (is_unowned && version > /** @type {import('#client').Derived} */ (reaction).version) {
198-
/** @type {import('#client').Derived} */ (reaction).version = version;
199-
return true;
197+
if (is_unowned) {
198+
if (version > /** @type {import('#client').Derived} */ (reaction).version) {
199+
/** @type {import('#client').Derived} */ (reaction).version = version;
200+
return true;
201+
} else if (!current_skip_reaction && !dependency?.reactions?.includes(reaction)) {
202+
// If we are working with an unowned signal as part of an effect (due to !current_skip_reaction)
203+
// and the version hasn't changed, we still need to check that this reaction
204+
// if linked to the dependency source – otherwise future updates will not be caught.
205+
var reactions = dependency.reactions;
206+
if (reactions === null) {
207+
dependency.reactions = [reaction];
208+
} else {
209+
reactions.push(reaction);
210+
}
211+
}
200212
}
201213
}
202214
}

0 commit comments

Comments
 (0)