Skip to content

Computed does not track dependencies if they are used later #13476

Closed as not planned
@neuronetio

Description

@neuronetio

Vue version

3.5.16

Link to minimal reproduction

https://play.vuejs.org/#eNp9Uk1v2zAM/SuELk2QLB/YTp1jbCt62A7bsPWoi+vIiVpZEiQqNWDov5eS6taHohdBfO9RfCQ1su/Wbi5BsGtW+dZJi+AFBltzLXtrHMIITnRraE1vA4ojROic6eGKkq645ro12iN00nn8J3xQCIeUsdgtv06km+P7THCtBBFBe4J3GSjadk/AVGyxWMKhhpFrgKQfiJtV2lwaFQQlA8gOFvm1GnbLkgBZXmrPlDEdSbpa5dhRu07DQEFMzqptmQNNgAIUvVUNCooAqvO+HsdkMUaoPoE2CMEeG5T6VG2JzKL7gGg0fGuVbB8PnBUHqxVn9c250ScxzWMcyyXGaluS6IFqOyvJ1gw9zaWTp82DN5q2lFvjLE1IKuH+WJQ0N86up6Y5a5QyT78yhi6I9YS3Z9E+voM/+CFhnP0lP8JdBGevHDbuJLDQt/9/i4Hur2RvjkGR+gOSFmVUSB6L7EfQR7I902W3P/NfozHe+dsBhfZTU8lo3lrWc0a/7uaD1t/sft58edl2ZPEZGXL3mQ==

Steps to reproduce

const firstResult = ref(0); const result = ref(10); let runs = 0; const c1 = computed(() => { let x = firstResult.value; const shouldTakeResult = runs > 0; // or Math.round(Math.random()) if (shouldTakeResult) { x = result.value; } runs++; return x; }); console.warn('c1', c1.value); result.value = 100; await nextTick(); console.warn('c1', c1.value); // computation is not triggered result.value = 1000; await nextTick(); console.warn('c1', c1.value); // nope, still 0

What is expected?

c1 should recompute

What is actually happening?

c1 does not recompute :)

System Info

Any additional comments?

I know I can add result somewhere before the "if" to let vue know I'm going to use this dependency, but not everyone knows about it and it can lead to bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions