Skip to content

Commit 0717058

Browse files
committed
fix: unset sub flags before propagate in trigger function
1 parent ab44e92 commit 0717058

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,15 @@ export function trigger(fn: () => void) {
193193
fn();
194194
} finally {
195195
activeSub = prevSub;
196-
while (sub.deps !== undefined) {
197-
const link = sub.deps;
196+
let link = sub.deps;
197+
while (link !== undefined) {
198198
const dep = link.dep;
199-
unlink(link, sub);
200-
if (dep.subs !== undefined) {
201-
propagate(dep.subs);
202-
shallowPropagate(dep.subs);
199+
link = unlink(link, sub);
200+
const subs = dep.subs;
201+
if (subs !== undefined) {
202+
sub.flags = ReactiveFlags.None;
203+
propagate(subs);
204+
shallowPropagate(subs);
203205
}
204206
}
205207
if (!batchDepth) {

tests/trigger.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,17 @@ test('should trigger effect once', () => {
4848
});
4949
expect(triggers).toBe(2);
5050
});
51+
52+
test('should not notify the trigger function sub', () => {
53+
const src1 = signal<number[]>([]);
54+
const src2 = computed(() => src1());
55+
56+
effect(() => {
57+
src1();
58+
src2();
59+
});
60+
trigger(() => {
61+
src1();
62+
src2();
63+
});
64+
});

0 commit comments

Comments
 (0)