Skip to content

fix(dev): setup data in nextTick is proxied to vm._data. #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/utils/instance.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 }
},
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