fix: ensure inspect effects are skipped from effect parent logic (#12810)

pull/12813/head
Dominic Gannaway 3 months ago committed by GitHub
parent 34ad016a77
commit fa5d3a9002
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure inspect effects are skipped from effect parent logic

@ -81,6 +81,14 @@ export function push_effect(effect, parent_effect) {
*/ */
function create_effect(type, fn, sync, push = true) { function create_effect(type, fn, sync, push = true) {
var is_root = (type & ROOT_EFFECT) !== 0; 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} */ /** @type {Effect} */
var effect = { var effect = {
@ -92,7 +100,7 @@ function create_effect(type, fn, sync, push = true) {
fn, fn,
last: null, last: null,
next: null, next: null,
parent: is_root ? null : current_effect, parent: is_root ? null : parent_effect,
prev: null, prev: null,
teardown: null, teardown: null,
transitions: null, transitions: null,
@ -130,8 +138,8 @@ function create_effect(type, fn, sync, push = true) {
effect.teardown === null; effect.teardown === null;
if (!inert && !is_root && push) { if (!inert && !is_root && push) {
if (current_effect !== null) { if (parent_effect !== null) {
push_effect(effect, current_effect); push_effect(effect, parent_effect);
} }
// if we're in a derived, add the effect there too // if we're in a derived, add the effect there too

@ -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]);
}
});

@ -0,0 +1,12 @@
<script>
let a = $state(0);
let b = $derived.by(() => {
$effect(() => {
a = 1;
})
return a;
})
$inspect(b);
</script>
Loading…
Cancel
Save