vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
46.94k stars 8.24k forks source link

Optimization of computed value is not working any more #11228

Closed alexzhang1030 closed 3 months ago

alexzhang1030 commented 3 months ago

Vue version

>=3.4.15, 3.4.13

Link to minimal reproduction

https://play.vuejs.org/#eNp9kk1PwzAMhv9KlAudKN0m4DK2STDtMA6AAHGKhKrO3TratEqcbVLV/46T7KNFaKc29uvHr53U/LGqoq0BPuJjnaisQqYBTTUVMiuqUiGrmYI0ZElZVAZhGbJdjMn68JmnKSTIGpaqsmBXBLoSUsiklBqpxEhkE1sfDHs2TuiFRFDbOA+CHptMWS0k88KIggbY9YQNhWxCNhwMBq7Iw1JJpCCKolittCsl2bmTN/flEJPT+dAklUGrRa9FVaBALkHNWlZ919Z4XautTp73YOMdUHcUwo37fre0VTogFFUeI9DpDByxuv4zR9N48o1H+zU5Xde21Y37LSoPOWoaMM1W0UaXki7XmRfcNshyUK8VZrQAwQlnMzYX53m5e3YxVAbCYzxZQ/LzT3yj9zYm+JsCTXcKgp9ySLcE6NPzjxfY0/8pWZRLk5P6QvIddJkb69HLnoxcku2WzrlduCeaydWnnu8RpD4OZY1aZeP0gtPDnF0Y/Wz3NrpzdXRvtMXvLSjLpAVSIhre8+YXrugTTQ==

Steps to reproduce

See re-render count

What is expected?

re-render count should always be 1, you can choose vue@3.4.14 and see.

What is actually happening?

If vue@^3.4.15, the re-render count always increases even if the computed value is unchanged.

System Info

No response

Any additional comments?

@johnsoncodehk implemented this feature in PR #5912

Doctor-wu commented 3 months ago

In your case, you access rerenderCount and mutate it immediately, this makes the effect always dirty, and then once you mutate the dependencies chain, this effect will always re-calc which is expected.