From 49013d7bfa81a966d449fb0509be71b51ad05263 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Sat, 21 Dec 2024 21:49:00 +0000 Subject: [PATCH 1/2] fix: ensure $inspect.trace indicated dirty traced deps correctly --- packages/svelte/src/internal/client/runtime.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 4a90a219712f..dc0d7dd1b0f6 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -528,6 +528,22 @@ export function update_effect(effect) { effect.teardown = typeof teardown === 'function' ? teardown : null; effect.version = current_version; + var version = current_version; + var deps = effect.deps; + + // In DEV, we need to handle a case where $inspect.trace() might + // incorrectly state a source dependency has not changed when it has. + // That's beacuse that source was changed by the same effect, causing + // the versions to match. We can avoid this by incrementing the version + if (DEV && (effect.f & DIRTY) !== 0 && deps !== null) { + for (let i = 0; i < deps.length; i++) { + var dep = deps[i]; + if ((dep.f & DERIVED) === 0 && dep.version === version) { + dep.version = increment_version(); + } + } + } + if (DEV) { dev_effect_stack.push(effect); } From cd2fd4a868bc271a9b1094edd5106a05f0a8cf1d Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Sat, 21 Dec 2024 21:59:38 +0000 Subject: [PATCH 2/2] fix: ensure $inspect.trace indicated dirty traced deps correctly --- .../svelte/src/internal/client/runtime.js | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index dc0d7dd1b0f6..d17d219397bd 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -524,21 +524,34 @@ export function update_effect(effect) { destroy_effect_deriveds(effect); execute_effect_teardown(effect); + + var sources; + var deps = effect.deps; + + if (DEV && tracing_mode_flag && deps !== null) { + sources = new Map(); + for (let i = 0; i < deps.length; i++) { + var dep = deps[i]; + if ((dep.f & DERIVED) === 0) { + sources.set(dep, dep.version); + } + } + } + var teardown = update_reaction(effect); effect.teardown = typeof teardown === 'function' ? teardown : null; effect.version = current_version; - var version = current_version; - var deps = effect.deps; + deps = effect.deps; // In DEV, we need to handle a case where $inspect.trace() might // incorrectly state a source dependency has not changed when it has. // That's beacuse that source was changed by the same effect, causing // the versions to match. We can avoid this by incrementing the version - if (DEV && (effect.f & DIRTY) !== 0 && deps !== null) { + if (DEV && tracing_mode_flag && (effect.f & DIRTY) !== 0 && deps !== null) { for (let i = 0; i < deps.length; i++) { - var dep = deps[i]; - if ((dep.f & DERIVED) === 0 && dep.version === version) { + dep = deps[i]; + if (sources?.has(dep) && sources.get(dep) !== dep.version) { dep.version = increment_version(); } }