Subscribe on changes!

Reactivity with ref() losts when transfer ref properties between the components

avatar
Aug 6th 2022

Vue version

latest, 3.2.37

Link to minimal reproduction

https://sfc.vuejs.org/#eNqtU02P2jAQ/StTXwISSbaVtpWygLTtqbeqWqkHzMEkDjGb2K7t8FGU/95xHFjKom0PPQT8MfPem/GbI3nUOtm2nGRkanMjtAPLXavnVIpGK+PgCIaX0EFpVAMRhkZUAgyXX1Sjww0lSep3HoySByqpzJW0DqQyDasfjWEHmHms0SJitogmUWEZ/v7c8Wg5fonPKybXvPgz4dc+9wnblRxyNtVzSEtT+KHMs4VSSA4rnrPWclAlWMdkwVDjhm1ZKI1KrO1JNFy1bjQaz+aXXMmW1S1PdGurkedDrmg8ub+7u0MWAP8h1+cWUYJQw3dGOF58lQPkK8nGaaEOJ+HlOq02D4P8+4+fjDucivDgV9JuoweRyLGghNmVpGQ5+RAkTtNQJL4cbhxvdM0cxx3A1D/Me0jn05Xpv/MhZFhLKdYzSo74ECgpu3ywjpL07eDLDl5FW3eoOcbmqlYmM7yg5BbC7ULPWL6wczFkQoLx4obpZGOVRN8e+7DhwlKSQX/iz3ovZrionNM2S1Nb5t6gG5sos05xlZhWOuRNuG3ilVE7yw0CU+IhOio7pDzZ+npGoMbasRRPejUvE/j+amiCa7RR2uIDFtwb9pvfTY+hK4PwU2MQYWqdEXK9WM5xoLpuPhrjv+9JwNoJV2HDPNUsACcBKQkYl3EhyFvzRuBf7FOIbb/A5bs4hqdKWNi9DJ2QwOoacma5jeNTJCbBNi6VwQ55Fh92S6NvnU8AOPae6LDrPUB6QTt4dhCAQwiS7x24nQK+14ZbK5RETTLCalEZ4M5whsdr+bakoTf/LOP/gJxmcDi/tHj3Gx0159g=

Steps to reproduce

Check the reporoduction link. After 2 seconds(timeout) element properties reassignes

What is expected?

Take care to 3rd component implementation in reproduction link(I marked it with red). All 3 divs in this component are expected to be replaced with a value that is reassigned on timeout.

What is actually happening?

This only works fine with the first element where the property is only provided by props.config.qwerty In other cases, the reactivity breaks. The property is provided with const theProperty = props.config.qwerty. But it won't work

System Info

No response

Any additional comments?

No response

avatar
Aug 6th 2022

That's expected behavior.

Note that if you destructure the props object, the destructured variables will lose reactivity. It is therefore recommended to always access props in the form of props.xxx.

https://vuejs.org/api/composition-api-setup.html#accessing-props

You can use toRef() to get a reactive single ref out of the props object.

https://vuejs.org/api/reactivity-utilities.html#toref

avatar
Aug 7th 2022

изображение изображение изображение

Seems like an issue.

avatar
Aug 7th 2022

Hard to debug a screenshot. Looks like an inconstency wirh thr types when using toRefs() on an optional property.

As rhis is unrelated to

avatar
Aug 7th 2022

Hard to debug a screenshot. Would assume it's just a type level inconstency with toRefs and an optional prop.

You could open separate issue for this.

toRef() will not have this problem.

avatar
Aug 7th 2022

toRef also have this problem. So ok, I will open a new issue