Skip to content

Commit

Permalink
fix(dev): setup data in nextTick is proxied to vm._data. (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed May 27, 2021
1 parent fcf8bc3 commit e231837
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils/instance.ts
Expand Up @@ -39,6 +39,9 @@ export function asVmProperty(
// expose binding to Vue Devtool as a data property
// delay this until state has been resolved to prevent repeated works
vm.$nextTick(() => {
if (Object.keys(vm._data).indexOf(propName) !== -1) {
return
}
if (isRef(propValue)) {
proxy(vm._data, propName, {
get: () => propValue.value,
Expand Down
28 changes: 28 additions & 0 deletions test/setup.spec.js
Expand Up @@ -942,6 +942,34 @@ describe('setup', () => {
expect(vm.$el.textContent).toBe('1')
})

// #679 html text change
it('should id not change when msg changed in development', async () => {
global.__DEV__ = true
const vm = new Vue({
template: '<div>{{ id }} {{ msg }}<button @click="change"/></div>',
setup() {
return { id: 42 }

This comment has been minimized.

Copy link
@carsoli

carsoli Aug 11, 2023

Contributor

so the id from the setup is completely ignored, in the case..

I can't find anything on the docs that warns that data from options api takes priority over what returns from setup

I realise it is an edge case and the user should bear responsibility but I can imagine such mistakes happening in a migration process so maybe docs/console warns would be great when a prop is duplicated on the setup return and the vm.$data

},
data() {
return {
id: 1,
msg: 'abc',
}
},
methods: {
change() {
this.msg = this.msg + this.id
},
},
}).$mount()

await nextTick()
expect(vm.$el.textContent).toBe('1 abc')
await vm.$el.querySelector('button').click()
await nextTick()
expect(vm.$el.textContent).toBe('1 abc1')
})

// #683 #603 #580
it('should update directly when adding attributes to a reactive object', async () => {
const vm = new Vue({
Expand Down

0 comments on commit e231837

Please sign in to comment.