Skip to content

Commit 9c5e708

Browse files
committed
fix: ensure unowned deriveds correctly get re-linked to the graph
1 parent 9285e7b commit 9c5e708

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,17 @@ export function check_dirtiness(reaction) {
205205
reaction.f ^= DISCONNECTED;
206206
}
207207

208-
var dirty = false;
208+
var unowned_dirty = false;
209209

210210
for (i = 0; i < dependencies.length; i++) {
211211
var dependency = dependencies[i];
212212

213-
if (!dirty && check_dirtiness(/** @type {Derived} */ (dependency))) {
213+
if (!unowned_dirty && check_dirtiness(/** @type {Derived} */ (dependency))) {
214214
update_derived(/** @type {Derived} */ (dependency));
215215
}
216216

217+
var version_mismatch = dependency.version > reaction.version;
218+
217219
// If we are working with an unowned signal as part of an effect (due to !skip_reaction)
218220
// and the version hasn't changed, we still need to check that this reaction
219221
// is linked to the dependency source – otherwise future updates will not be caught.
@@ -224,16 +226,15 @@ export function check_dirtiness(reaction) {
224226
!dependency?.reactions?.includes(reaction)
225227
) {
226228
(dependency.reactions ??= []).push(reaction);
227-
}
228-
229-
if (dependency.version > reaction.version) {
230-
// We can't just return here as we might have other dependencies that are unowned
231-
// ad need to be linked to the reaction again
232-
dirty = true;
229+
if (version_mismatch) {
230+
unowned_dirty = true;
231+
}
232+
} else if (version_mismatch) {
233+
return true
233234
}
234235
}
235236

236-
if (dirty) {
237+
if (unowned_dirty) {
237238
return true;
238239
}
239240
}

0 commit comments

Comments
 (0)