Subscribe on changes!

`triggerRef` reactivity breaks when contents of `shallowRef`'s inner value are passed to child components via props

avatar
Oct 12th 2023

Vue version

3.3.4

Link to minimal reproduction

https://play.vuejs.org/#eNqtVllvGzcQ/iuDLQqtG2nXaZoXVXLrOnlwEbRGmj5FeVgvuRJtLknw0AFB/73DYw83toAGNWyYmovffHNQx+xaqWLraDbPFpa2ileWXq0EwKKtmAgnPN87a6WIHwDsQdHlKkvCrBP/WnNWP6LCKYJRbjGc6bQpEMA76e45BbuhUEsnrEk3lDEa2iUBYdveaaGuPm2ooRAjo6fWtLb8UCxKNVg53p/xE2fDB4DtrJEasTFEBbIB/79HF3/mj/SQLApGxrpRWIAbD3sOx2OIUYQs4HQa3VxyNoAqe1SLMuZ0LkEixcSey+oDM9Yz+7/lhjovTcqxpjyXhD+lDlmUo8bBj6bWTFkw1DoFvBJrjI11zoIXa5XUFo6wq2y9gRM0WrYwwQ6c/DzSd2kmdVF2At+rTyyP4EzstT5YUXYib+ltaykMmsYUAj3TeB61apCcYNnHyy+Sd4CaRzfIL2B51YXycSWnBZfrfPI5jdIXiFxiyvDg8N56gyRQMvHx8IopYm64M5s5TMxB1BM4ec2ijMQlEu2Bx0H8rlKqu48wg0Qf5uhP9yEaQMXZWszChXOoqbBUx3sieF+kr9zXmpHk7o+zroCzWnLXCgz0utH+Lxm1lV4zMYefLtUeKmdlJ2ditmPEYipvL1GXxBvK1hucEa9GiiyCGkOKo96BCgDivXgtlDB7PTZ2vDPsQFymW1RFCBPrQcCxR2aBuJmShlkm0ZoJwwjtIiLJidhsik2J4Bq2Lh6MFLgAwz2rrJatYpzqP5WPgFXEYY8XrLKKc7n7PcisdjR1EfpsaP34jPzB7L1sld1pHG+9paus11nMh9qofv/XH3SP517ZSuI4Wp9RfqTYe85jjGa/OUEQ9sguoL0Nc4JEfTLv91gK0yXlgcaGjHlj696cSX2A+6Z4k+g8IYvjyfz6FelX4Zm1mRbmt+0RKf4OM0ymgPBuHL4Mwt7iuFeipi/uF/+EoXNYMS+vDUIbJuidlsosRstjHvxiS131W6IHkr+8Ivq1tmN2A7fvkNbvcRunNUQmz+WQX/xSOEbS8vjXpkD+O9CFNUh/z4vZhOp/pM0UK83Wa6rD+dm9uxJ0P/ASEC5jAozMQbj2Pi2VULaR5DR2bpyofd8MGxmZCFE4tTiIhO4xrJ9WLyvLJxjvaV2hH+zwt8LW8N8QwlIDpKYCK9ECjFNUA/7hg9ei1RSMBCHFDGu0Z5QUw7KPvsvRHQuP6fOXqzwW5lrr6pC/vegeuaJhnOc4Q6HoZJC3lUolzVNNQyMgMa9ehaTSvMVqB36eik8XIdh/fU46Fr/xPfG6oSLDO9cXJZTgA7UTA0pT3AwESWcGGor4KAFBd4nF0CuVgOu72+iI9EM+8Nx/6Si2FXe0jx/HJc36D0v4MS3qtNrxm2TfmJGPlFFUIyan+2fi7KvtOxGH4fQP27lyug==

Steps to reproduce

Click the "Double the counts" button. Watch the counts change.

What is expected?

Both lists update.

What is actually happening?

The left list updates the counts, but the right list doesn't.

System Info

Any system, any browser.

Any additional comments?

No response

avatar
Oct 12th 2023

Possibly the same as #6273? If it is, then I understand this is by design.

How would one handle this case though:

  • Get huge array with large amounts of data from e.g. an API/JSON
  • Don't make the whole array recursively reactive (use a shallowRef), but let Vue know whenever it should rerender template content that uses the array or any of its contents.

I suppose it doesn't really make sense to expect non-reactive data to magically become reactive without wrapping everything in Proxies, but maybe there's a way and I just don't know about it?

avatar
Oct 13th 2023

This is by design, yes. The best way to deal with this scenario would likely be to use immutable data a la React etc.

avatar
Oct 13th 2023

Appreciate the fast reply! Could you eleborate on this immutable data pattern and how to apply it in Vue? Do you mean working with readonly? Object.freeze? Or more like https://vuejs.org/guide/extras/reactivity-in-depth.html#immutable-data?

avatar
Oct 13th 2023

The latter. Its basically about not mutating objects, but instead always creating new copies that contain the changes from the previous version

avatar
Oct 13th 2023

I'll close this issue as it's not a bug. Feel free to reach out for more input in this repo's "Discussions" section or on our Discord chat.