Array mutation methods no longer trigger a watcher on Vue 2.7

This issue has been created since 2022-10-12.

Version

2.7.11

Reproduction link

codesandbox.io

Steps to reproduce

const someArray = ref([])
watch(someArray, () => { console.log('mutated') })
const action = () => someArray.push('new')

What is expected?

When executing the action and an item is pushed into the array, on Vue 2.6 with composition api plugin it was triggering the watcher

What is actually happening?

on Vue 2.7 it no longer triggers the watcher


On my real case I'm actually watching () => store.state.someArray, but it's the same issue I guess.
I simplified the repro with a ref.
On Codesandbox repro, click the "add" button to push an item into array and it should display an alert window from the watcher.

yyx990803 wrote this answer on 2022-10-15

This is expected behavior and consistent with Vue 3.

Note your example of using a ref is slightly different from () => store.state.someArray.

  • In the case of ref([]), the watcher only fires if the ref's value changes, i.e. the array is replaced. It does not watch deep mutations of the array itself.
  • In the case of () => store.state.someArray, the watcher only fires if someArray is replaced. Similarly it does not watch deep mutations.

If you want to watch array mutations, you need to explicitly use a deep watcher.

The Composition API plugin behavior is different from Vue 3 and thus should be considered a bug.

More Details About Repo
Owner Name vuejs
Repo Name vue
Full Name vuejs/vue
Language TypeScript
Created Date 2013-07-29
Updated Date 2022-12-10
Star Count 201155
Watcher Count 6070
Fork Count 33134
Issue Count 595

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
有没有人遇到:1路1080p流在下载,解复用,音视频解码,播放出现卡顿 后一直卡在 loading里问题 2 2021-01-27 2022-07-07
[FEATURE REQUEST] Allow installing apps via Aurora Services. 2 2022-09-24 2022-12-05
visual bug on app page - text wrapping 4 2022-09-29 2022-12-05
Installed apps more sorting 0 2022-09-22 2022-12-05
How to control the sensitivity of Gyroscope Plugin 5 2022-06-10 2022-11-10
Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'. 1 2022-06-10 2022-11-10
Fail on Recognizing URLs Containing Specific Strings 1 2021-12-05 2022-10-06
feature request: -f like option, but the last one processed 3 2021-07-12 2022-12-08
Links to pretrained weights broken? 1 2021-06-21 2022-11-13
error: ARCtool.exe failed with status code 3221226519 1 2022-01-25 2022-09-14
does this plugin has a minimum android sdk version it can work for? 26 2021-01-19 2022-11-30
Add cancellation token? 1 2022-04-12 2022-09-09
AuthorizeWith attribute on graph type does not fire authentication 4 2022-04-09 2022-09-10
ADMIN: change maintainers of the libseccomp-golang project 14 2020-03-12 2022-12-03
Deprecated message doesn't show in doc 0 2022-08-23 2022-11-24
supporting HDR without iina plus 1 2022-07-17 2022-11-03
Question about visitors 2 2021-06-20 2022-12-05
[Site Request] Krhentai 1 2022-02-22 2022-07-17
[Site Request] Muamh 1 2022-02-22 2022-09-21
Allow missing tag level 2 2020-01-17 2022-11-27
timeScale.fitContent is not working correctly 4 2022-01-06 2022-10-08
Question regarding stf deployment using stf commands instead of docker 9 2016-08-31 2022-12-06
Destination Pubsub: failed integration tests 0 2022-02-01 2022-09-30
feat: How to disable rendering of html code in markdown code blocks? 2 2022-08-25 2022-11-10
bitwarden.com has no CSP 1 2022-06-10 2022-12-02
'No Folder' view shows all items 1 2022-06-06 2022-12-02
`process.Connections()` does not return `unix` connections, but `net.Connections()` does 0 2021-08-16 2022-11-07
Code simplicity (Max Kanat-Alexander) 1 2022-07-30 2022-11-25
High memory usage 1 2021-08-03 2022-01-07
Horizontal scroll wheel scrolls vertically 1 2021-07-28 2022-10-20
Conimex import fails when collection is empty 4 2022-08-17 2022-11-20
can add cron job in controller? 1 2019-12-10 2022-11-14
[Mobile Payments] Intermittently "We couldn’t connect your reader" with UnderlyingError bluetoothDisconnected 1 2021-11-17 2022-10-18
Document adding additional InputPaths in Statiq Web 0 2021-10-15 2022-10-11
Short Circuit Visitors - IvaratorRequired 2 2022-03-28 2022-12-05
[BUG] CHANGELOG.md doesn't document version 9.x.x 1 2021-06-14 2022-11-15
Get ABC building again on Windows 0 2021-09-03 2022-11-17
Get Yices building on Windows at all 0 2021-09-03 2022-10-07
Selecting option with controlled input value and `controlShouldRenderValue={false}` temporarily results in blank input 4 2022-04-04 2022-11-25
Ubuntu WSL graphical setup fails 2 2022-08-29 2022-11-27
(jkube-kit-watcher-api): Replace JUnit4 with JUnit5 1 2022-06-14 2022-11-11
Try in PWD not working 3 2022-07-25 2022-12-03
Still show Jenkins agent pod resource usage footprint after pod down 0 2021-07-30 2022-12-09
Minimum version check should be 5.0 not 3.0 1 2021-06-21 2022-11-30
enable race detection 0 2021-11-21 2022-07-12
Unit Tests - Relationship Support for Self Referential Many to many 5 2021-09-16 2022-11-30
求vscode版本插件支持~ 1 2020-04-02 2022-01-17
public_access_prevention documentation missing 3 2022-02-11 2022-11-14
Update `master` branches to `main` in TPG, TPGB and magic-modules. 1 2022-02-11 2022-10-07
[Material Icons] Water drop icons are not properly rendered. 2 2021-12-28 2022-07-25