vuejs / pinia

🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
https://pinia.vuejs.org
MIT License
12.91k stars 1.02k forks source link

$subscribe doesn't trigger if only computed is returned from the store #2594

Closed bertBruynooghe closed 6 months ago

bertBruynooghe commented 6 months ago

Reproduction

https://play.pinia.vuejs.org/#eNqNVMtu2zAQ/BVCKCAlsEkbaXMI4iBtkUN7aIskt6oH2VrbTCiS4MMRYOjfuyQtWU7TohdB3MfscMjhPvuoNd15yK6ya7syXDtiwXlNRCU3izJztsxuSskbrYwje+ItPDhlgHRkbVRDcspsWFNn81GZgfVQgeiYKuVKSeuIA/wsQkExOzuGIwjGe/wCcwn4nfXLwGwJRXFGFjdkX0oSYeiuEj40zUvZYf01SztAvrhw0GhROcAVIft9aOi6kAmrA2eMfVaN9g7qkLtmQ1M2ydJmpk2l6ZNVEhWKk8tDAoW5SlxCTHPJqxApMxb/KdhmujTqxYLB/jKb9KW3KAirYeeUEnZaaZ7ats5pe8XYqpZYX4PgO0MlOCZ1w/7oub2kH+icCb5kOIhxWUN7OgY7pjU0/4Pel97O6Pw9vYyou4sDaBNQAygK1KEszuKJrfnmlSgr1JELMN+143iiJ+JUQqiXrzHmjIeB4moLq+c34k+2Tax/GED5djDalqvMBlxK3z18gxb/h2Sjai+w+h/Je7BK+MAxlX3yskbao7rI9ks8Yy43j/audSBtv6lANKoR66PM4Qr9betHuhf0YqRibxoUcDBNDWsuX9kr3qWxs4LO4b5O3vQYtLEseWrw6mIMXeRxdj4hIzsdvXmPqMmeP3+hp8ap3iqY71mMLZlKlQAq1KbIl7BOYw6oya0RkiC+80aepqI68Ukg4Q165A0o704nnDRQ7e22yNu2zQ+wJwRcAniTQTch89ksPUADmz05Dun3ergV7HwQ55wRxghfE7cFfLbwsSDckqquw5nEWP9ekRdlnm1/6GdZ9xspcNOm

Steps to reproduce the bug

  1. create a store that publishes computed property and state
  2. reference the computed property in the calling code
  3. subscribe to the store
  4. change the state so the computed property code is executed again => subscription is triggered
  5. unpublish the state from the store
  6. change the state so the computed property code is executed again

Expected behavior

subscription is triggered

Actual behavior

subscription is not triggered

Additional information

No response

posva commented 6 months ago

You have to return the state alongside the ref. This is mentioned in the docs