The documentation for batchedEffect() says: "The effect also runs asynchronously, on the microtask queue, if any of the signals it depends on have been updated outside of a batch() call."
This works once, but after the first update outside of batch() the effect no longer runs for any additional signal updates (whether inside or outside a batch() call).
import { Signal } from "signal-polyfill"; // 0.2.2
import { batch, batchedEffect } from "signal-utils/subtle/batched-effect"; // 0.21.1
const a = new Signal.State(0);
const b = new Signal.State(0);
batchedEffect(() => {
console.log(`a + b = ${a.get() + b.get()}`);
}); // logs a + b = 0
batch(() => {
a.set(1);
b.set(1);
}); // logs a + b = 2 (single, synchronous batched effect)
a.set(2); // update outside batch(), logs a + b = 3
await 0; // flush microtask queue
// Bug: after an update outside batch(), batchedEffect no longer runs
b.set(2); // should log a + b = 4; actually logs nothing
It looks like maybe the async case fails to re-enable the watcher.
Demo: https://codepen.io/mvedmunds/pen/xbOpbXV?editors=0011
Using signal-polyfill@0.2.2 and signal-utils@0.21.1
The documentation for
batchedEffect()says: "The effect also runs asynchronously, on the microtask queue, if any of the signals it depends on have been updated outside of abatch()call."This works once, but after the first update outside of
batch()the effect no longer runs for any additional signal updates (whether inside or outside abatch()call).It looks like maybe the async case fails to re-enable the watcher.
Demo: https://codepen.io/mvedmunds/pen/xbOpbXV?editors=0011
Using signal-polyfill@0.2.2 and signal-utils@0.21.1