-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Unhandled error during execution of watcher callback and scheduler flush #2170
Comments
Does this only happen in the test, but works fine when using the code in an app? Then that mit be something related to the test-utils. I can transfer the issue if so. |
When using the component that the aforementioned test file is testing in a Vue app, it doesn’t render without issues. The most glaring issue is that in the Now I’m not certain that either of those issues is necessarily related to what I reported initially. It might be that I’ve done something wrong when migrating the consuming app to Vue 3 or something of my tooling dependencies isn’t quite ready to be used with Vue 3, yet. But also, both the component that is the subject of the report above and the consuming app are relatively small and basic. I’ll try to reduce the test setup for this to figure out more. |
Here's a minimal reproduction: Click the increment button and open the console: |
I can confirm a similar issue while trying to migrate a v2 codebase to v3. Inside of a component watcher I expect this.$el to be set, but it is null. |
I'm having the same problem also when migrating from v2 to v3 |
|
In my naïve hopes to possibly fix this myself, I wrote a two test cases which — as far as I understand — should both pass:
Both should have access to the instance’s should have access to instance’s “$el” property in watcher when setting instance data// #2170
test('should have access to instance’s “$el” property in watcher when setting instance data', async () => {
function returnThis(this: any) {
return this
}
const dataWatchSpy = jest.fn(returnThis)
let instance: any
const Comp = {
data() {
return {
testData: undefined
}
},
watch: {
testData() {
// @ts-ignore
dataWatchSpy(this.$el)
}
},
created() {
instance = this
},
render() {
return h('div')
},
}
const root = nodeOps.createElement('div')
render(h(Comp), root)
expect(dataWatchSpy).not.toHaveBeenCalled()
instance.testData = 'data'
await nextTick()
expect(dataWatchSpy).toHaveBeenCalledWith(instance.$el)
}) This test passes. should have access to instance’s “$el” property in watcher when rendereing with watched prop'// #2170
test('should have access to instance’s “$el” property in watcher when rendereing with watched prop', async () => {
function returnThis(this: any) {
return this
}
const propWatchSpy = jest.fn(returnThis)
let instance: any
const Comp = {
props: {
testProp: String
},
watch: {
testProp() {
// @ts-ignore
propWatchSpy(this.$el)
}
},
created() {
instance = this
},
render() {
return h('div')
},
}
const root = nodeOps.createElement('div')
render(h(Comp), root)
await nextTick()
expect(propWatchSpy).not.toHaveBeenCalled()
render(h(Comp, { testProp: 'prop ' }), root)
await nextTick()
expect(propWatchSpy).toHaveBeenCalledWith(instance.$el)
}) This test fails because |
I now understand @LinusBorg’s investigation and think I can provide a fix for this. If that’s alright, I’d like to submit a pull request for this. |
Version
3.0.0
Reproduction link
https://codesandbox.io/s/vigorous-nash-8lxt8?file=/src/Child.vue
Steps to reproduce
What is expected?
this.$el
should be defined inside of the watcher like in Vue 2What is actually happening?
it is null
The text was updated successfully, but these errors were encountered: