Skip to content

Inconsistent behavior using reactive and ref objects #12643

@Flamenco

Description

@Flamenco

Version

2.7.4

Reproduction link

Vue 2
codesandbox.io
Vue 3
codesandbox.io

Steps to reproduce

The documentation for Vue 2.7 states there are issues using a reactive array. This report is when using an empty reactive object. Either the documentation and warnings need to be updated, or the implementation corrected.

Avoid using arrays as root values in reactive()
because without property access the array's mutation won't be tracked
(this will result in a warning).

Because I am using an object, not an array, no warnings are generated.

Here are the differences I get when using Vue 2.7.x versus Vue 3.x:

const reactiveData = reactive({});
const refData = ref({});

Vue 3

reactiveData.foo = 'bar' 
refData.value.foo = 'bar'
  • reactive watcher called
  • reactive deep watcher called
  • ref watcher NOT called
  • ref deep watcher called

Vue 2

set(reactiveData, 'foo', 'bar')
set(refData.value, 'foo', 'bar')
  • reactive watcher NOT called
  • reactive deep watcher NOT called
  • ref watcher called
  • ref deep watcher called

What is expected?

Watchers/Reactivity should be consistent.

What is actually happening?

Watchers/Reactivity is not consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions