preactjs / preact-www

:book: Preact documentation website.
https://preactjs.com
MIT License
358 stars 500 forks source link

REPL: Bug with `effect` & `useSignalEffect` tracking #1180

Open rschristian opened 3 weeks ago

rschristian commented 3 weeks ago

Not quite sure of the cause & don't have time to chase it down yet, but the tracking of dependencies in effect and useSignalEffect seems to be a bit broken in the context of our REPL. For example, here's a lazy effect:

import { signal, effect, useSignalEffect } from '@preact/signals';

const count = signal(0);
const initialized = signal(false);

effect(() => {
    count.value;
    if (!initialized.peek()) return initialized.value = true;
    console.log(count.value)
});

count.value++;

The effect here will not subscribe to count, even though it's explicitly accessed. Swapping that to count.value.toString() works, however.