Skip to content

Commit 308c921

Browse files
committed
Add changeset
1 parent 6605f56 commit 308c921

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.changeset/big-fans-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@preact/signals-core": minor
3+
---
4+
5+
Prevent batches where a signal goes from A --> B --> A from triggering dependent updates, a computed/effect should not re-run when the dependencies in a batched update amount to an equal value.

packages/core/test/signal.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,29 @@ describe("effect()", () => {
870870
expect(spy).not.toHaveBeenCalled();
871871
});
872872

873+
it("should not rerun an effect for repeated no-op top-level batches", () => {
874+
const foo = signal(42);
875+
const spy = vi.fn(() => {
876+
foo.value;
877+
});
878+
879+
effect(spy);
880+
expect(spy).toHaveBeenCalledOnce();
881+
spy.mockClear();
882+
883+
batch(() => {
884+
foo.value = 0;
885+
foo.value = 42;
886+
});
887+
expect(spy).not.toHaveBeenCalled();
888+
889+
batch(() => {
890+
foo.value = -1;
891+
foo.value = 42;
892+
});
893+
expect(spy).not.toHaveBeenCalled();
894+
});
895+
873896
it("should not rerun parent effect if a nested child effect's signal's value changes", () => {
874897
const parentSignal = signal(0);
875898
const childSignal = signal(0);

0 commit comments

Comments
 (0)