Skip to content

Commit

Permalink
fix(reactivity): properly avoid effect recurse
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Jan 12, 2024
1 parent bb6b7a2 commit 595bae8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/reactivity/__tests__/computed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ describe('reactivity/computed', () => {
expect(c1.value).toBe(1)
})

it('should work when chained(ref+computed)', () => {
const value = ref(0)
const provider = computed(() => value.value + consumer.value)
const consumer = computed(() => {
value.value++
return 'foo'
})
provider.value
expect(provider.value).toBe('1foo')
})

it('should trigger effect when chained', () => {
const value = reactive({ foo: 0 })
const getter1 = vi.fn(() => value.foo)
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function triggerEffects(
) {
pauseScheduling()
for (const effect of dep.keys()) {
if (!effect.allowRecurse && effect._runnings) {
if (!effect.allowRecurse && effect._runnings && effect === activeEffect) {
continue
}
if (
Expand Down

0 comments on commit 595bae8

Please sign in to comment.