Skip to content

Commit da3dc27

Browse files
committed
fix: it should not break a computed signal to watch it before getting its value
1 parent aeeb2bd commit da3dc27

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/graph.ts

-6
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,6 @@ export function producerIncrementEpoch(): void {
274274
* Ensure this producer's `version` is up-to-date.
275275
*/
276276
export function producerUpdateValueVersion(node: ReactiveNode): void {
277-
if (consumerIsLive(node) && !node.dirty) {
278-
// A live consumer will be marked dirty by producers, so a clean state means that its version
279-
// is guaranteed to be up-to-date.
280-
return;
281-
}
282-
283277
if (!node.dirty && node.lastCleanEpoch === epoch) {
284278
// Even non-live consumers can skip polling if they previously found themselves to be clean at
285279
// the current epoch, since their dependencies could not possibly have changed (such a change

tests/Signal/subtle/watcher.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,16 @@ describe("Watcher", () => {
178178
signal.set(1);
179179
expect(mockGetPending).toBeCalled();
180180
});
181+
182+
it("should not break a computed signal to watch it before getting its value", () => {
183+
const signal = new Signal.State(0);
184+
const computedSignal = new Signal.Computed(() => signal.get());
185+
const watcher = new Signal.subtle.Watcher(() => {});
186+
expect(computedSignal.get()).toBe(0);
187+
signal.set(1);
188+
watcher.watch(computedSignal);
189+
expect(computedSignal.get()).toBe(1);
190+
watcher.unwatch(computedSignal);
191+
expect(computedSignal.get()).toBe(1);
192+
});
181193
});

0 commit comments

Comments
 (0)