diff --git a/.changeset/stupid-cars-behave.md b/.changeset/stupid-cars-behave.md new file mode 100644 index 0000000000..9612cb3a86 --- /dev/null +++ b/.changeset/stupid-cars-behave.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure inspect effects are skipped from effect parent logic diff --git a/packages/svelte/src/internal/client/reactivity/effects.js b/packages/svelte/src/internal/client/reactivity/effects.js index 9fd238c866..d05243bb14 100644 --- a/packages/svelte/src/internal/client/reactivity/effects.js +++ b/packages/svelte/src/internal/client/reactivity/effects.js @@ -81,6 +81,14 @@ export function push_effect(effect, parent_effect) { */ function create_effect(type, fn, sync, push = true) { var is_root = (type & ROOT_EFFECT) !== 0; + var parent_effect = current_effect; + + if (DEV) { + // Ensure the parent is never an inspect effect + while (parent_effect !== null && (parent_effect.f & INSPECT_EFFECT) !== 0) { + parent_effect = parent_effect.parent; + } + } /** @type {Effect} */ var effect = { @@ -92,7 +100,7 @@ function create_effect(type, fn, sync, push = true) { fn, last: null, next: null, - parent: is_root ? null : current_effect, + parent: is_root ? null : parent_effect, prev: null, teardown: null, transitions: null, @@ -130,8 +138,8 @@ function create_effect(type, fn, sync, push = true) { effect.teardown === null; if (!inert && !is_root && push) { - if (current_effect !== null) { - push_effect(effect, current_effect); + if (parent_effect !== null) { + push_effect(effect, parent_effect); } // if we're in a derived, add the effect there too diff --git a/packages/svelte/tests/runtime-runes/samples/inspect-nested-effect/_config.js b/packages/svelte/tests/runtime-runes/samples/inspect-nested-effect/_config.js new file mode 100644 index 0000000000..82429e5e36 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/inspect-nested-effect/_config.js @@ -0,0 +1,11 @@ +import { test } from '../../test'; + +export default test({ + compileOptions: { + dev: true + }, + + async test({ assert, logs }) { + assert.deepEqual(logs, ['init', 0, 'update', 1]); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/inspect-nested-effect/main.svelte b/packages/svelte/tests/runtime-runes/samples/inspect-nested-effect/main.svelte new file mode 100644 index 0000000000..3693e4f6d5 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/inspect-nested-effect/main.svelte @@ -0,0 +1,12 @@ + +