fix: ensure effect_tracking correctly handles tracking reactions (#14005)

* fix: ensure effect_tracking correctly handles tracking reactions

* fix: ensure effect_tracking correctly handles tracking reactions
pull/14015/head
Dominic Gannaway 2 months ago committed by GitHub
parent 777d059b10
commit 3876b302f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure effect_tracking correctly handles tracking reactions

@ -15,7 +15,8 @@ import {
set_is_destroying_effect,
set_is_flushing_effect,
set_signal_status,
untrack
untrack,
skip_reaction
} from '../runtime.js';
import {
DIRTY,
@ -167,7 +168,9 @@ export function effect_tracking() {
return false;
}
return (active_reaction.f & UNOWNED) === 0;
// If it's skipped, that's because we're inside an unowned
// that is not being tracked by another reaction
return !skip_reaction;
}
/**

@ -0,0 +1,19 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, target, logs }) {
let btn1 = target.querySelector('button');
btn1?.click();
flushSync();
btn1?.click();
flushSync();
btn1?.click();
flushSync();
assert.deepEqual(logs, ['light', 'dark', 'light']);
}
});

@ -0,0 +1,13 @@
<script>
import { store, themeState } from './theme.svelte.js';
let i = 0;
const increment = () => {
store.update(() => ({ theme: ++i % 2 == 0 ? 'dark' : 'light' }));
}
</script>
<button onclick={increment}>+</button>
{themeState.value.theme}

@ -0,0 +1,18 @@
import { fromStore, writable } from 'svelte/store';
export const store = writable({ theme: 'dark' });
class ThemeState {
#storeState = fromStore(store);
value = $derived(this.#storeState.current);
constructor() {
$effect.root(() => {
$effect(() => {
console.log(this.value.theme);
});
});
}
}
export const themeState = new ThemeState();
Loading…
Cancel
Save