Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reactivity): triggerRef working with toRef from reactive #7507

Merged
merged 4 commits into from Feb 1, 2023

Conversation

antfu
Copy link
Member

@antfu antfu commented Jan 11, 2023

triggerRef allows forcing update the ref created by ref and shallowRef, but not the one from toRef.

For example

const foo = ref(1)

watchEffect(() => {
  console.log('update foo', foo.value)
})

triggerRef(foo) // triggers
const state = reactive({ foo: 1 })
const foo = toRef(state, 'foo')


watchEffect(() => {
  console.log('update foo', foo.value)
})

triggerRef(foo) // does not triggers

It's because the ref created by toRef did not forward the .dep attribute. This PR fixes it.

Playground Before:

https://sfc.vuejs.org/#eNp9kU1ugzAQha8y8gaiEGi7RCRSr1B16Q2BISENtjU2tBLy3Ts2JU1bqRvwvHn+PD+zeDYmn0YUpahsQ71xYNGN5iBVPxhNDmYg7DL+1I3rJ8yg0YMZHbYZOOpPJ6SXkHc6/hR+uNe+eQMPHekBEmYnUknVaGWZ7WqHsL/R0hk6rUt4BL9ZPSywI/LS6M8gYS1hA8BqavSoXAR16cOPzLEm1tci03QD+wPMwRHv5FN9HRG226AQt0oqvLjIUoUypFq7uL/93WzKfrYFa1UsQ+NxceBwMFcumCOAqu2nAxdTwjzHoryviqDdkqNp2RzzSzveQ2rPery2cER42qz+qriRRSaWveyG2uQXqxVvLtYnvxJWCkYGJWg8/hBLcXbO2LIobNeEfV9srulU8CknfrofMEc77I6k3y0Sg6XI7hgFixPSjlC1SEj/MX9Z/3AD1vP4hP8EmTTcTA==

Playground After:

https://deploy-preview-7507--vue-sfc-playground.netlify.app/#eNqlUcFOwzAM/RUrl3WiaQEJIU1lEr+AOObSte4WaJPISTumqv+O09Ex4MillZ9f3nu2R/HsXDb0KDai8BVpF8Bj6N1WGd05SwFGIGxS/pRV0AOmUNnO9QHrFALp/R7pJfaDnX8GP8Krrt5hgoZsByvWXimjTGWNZ+1QBoSni1oyQmPtBu5gWi8cBpgx6yUzP4UVYysmACykyvYmzEJNcvujsyuJ8SVkkqzhaQtjZMxvsqFse4Sbm4gQj0omOp5hZWIMZZYprl9/D5swn2mRWuTnpfG6uAjYuZYDcwVQ1HrYcpgNjOMcapqKPGKXZu9qJs/98zjTBIk/2L6tYYdwv174RX5RFqk430V2pcvevDV8uTmf+mp4JVgyIhHj9cdaiUMIzm/yvEbX2pN0hIPGo3x8uH2UklnSN5Vkj9OeOEudGQytbk5Z6VzO7Yw4oO4wQ9/JHdmjR2J7JdIrp5zBAUkSmhoJ6f/OvwT/uEfziU8hpk8bZPfk

@antfu antfu added the 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. label Jan 12, 2023
@yyx990803 yyx990803 merged commit e64c9ae into main Feb 1, 2023
@yyx990803 yyx990803 deleted the fix/trigger-ref-reactive branch February 1, 2023 08:20
zhangzhonghe pushed a commit to zhangzhonghe/core that referenced this pull request Apr 12, 2023
…js#7507)

* fix(reactivity): `triggerRef` working with `toRef` from reactive

* chore: refactor
IAmSSH pushed a commit to IAmSSH/core that referenced this pull request May 14, 2023
…js#7507)

* fix(reactivity): `triggerRef` working with `toRef` from reactive

* chore: refactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants