Skip to content
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 native event handler #5180

Closed
adamreisnz opened this issue Dec 28, 2021 · 5 comments
Closed

Unhandled error during execution of native event handler #5180

adamreisnz opened this issue Dec 28, 2021 · 5 comments

Comments

@adamreisnz
Copy link

adamreisnz commented Dec 28, 2021

Version

3.2.26

Reproduction link

sfc.vuejs.org/

Steps to reproduce

  1. Create an @click handler
  2. Generate an error in the actual handler
  3. Observe that Vue issues a warning "Unhandled error during execution of native event handler"

What is expected?

For the actual error to be surfaced/logged/exposed to make debugging easier

What is actually happening?

The warning doesn't contain any meaningful information and makes debugging challenging.


I can't seem to reproduce this in the SFC playground, as I see the actual error surfacing there (e.g. Cannot read properties of undefined (reading 'defaultPrevented')), but when I do something similar in my app Vue keeps reporting the warning "Unhandled error during execution of native event handler" and the actual error is not shown or logged.

@LinusBorg
Copy link
Member

LinusBorg commented Dec 28, 2021

You must have a problem with your project setup, as this is what I see:

image

...and you see a stack trace in the playground as well.

Feel free to open a new issue here (or maybe in the Vue CLI repo, depending on your setup?) when you have a runnable reproduction repository.

Or ask for help in the community at chat.vuejs.org

@adamreisnz
Copy link
Author

adamreisnz commented Dec 29, 2021

My bad, you were right this was environmental. Turned out the event default was being prevented in the unhandledrejection listener with event.preventDefault()

Sorry for the noise, will leave this up in case someone else stumbles upon a similar issue.

@BrunoRicci
Copy link

BrunoRicci commented Jan 25, 2022

My bad, you were right this was environmental. Turned out the event default was being prevented in the unhandledrejection listener with event.preventDefault()

Sorry for the noise, will leave this up in case someone else stumbles upon a similar issue.

I'm facing the same issue and cannot seem to solve it. I get the same error over and over.

my html element has this attribute: @click="componentClicked"
and the method is in the "methods" object at the "script" section of the vue SFC.

componentClicked:(event)=>{ event.preventDefault(); console.log('Line clicked', event); this.$emit('line-click'); }

The componentClicked method works fine, and the "event" value is properly printed in the console. Apparently that component's line this.$emit('line-click'); is the problem, this is the actual error I get, plus the warning you also had.
imagen

@BrunoRicci
Copy link

My bad, you were right this was environmental. Turned out the event default was being prevented in the unhandledrejection listener with event.preventDefault()
Sorry for the noise, will leave this up in case someone else stumbles upon a similar issue.

I'm facing the same issue and cannot seem to solve it. I get the same error over and over.

my html element has this attribute: @click="componentClicked" and the method is in the "methods" object at the "script" section of the vue SFC.

componentClicked:(event)=>{ event.preventDefault(); console.log('Line clicked', event); this.$emit('line-click'); }

The componentClicked method works fine, and the "event" value is properly printed in the console. Apparently that component's line this.$emit('line-click'); is the problem, this is the actual error I get, plus the warning you also had. imagen

Well, I finally found my mistake; I was calling "this" from an arrow function and not from the function itself... thus, "this" wasn't accessible. I came up with this kind of error once and spent hours dealing with it, but this time I recalled about it and instantly realized.

I hope it will be useful for anyone who is perhaps facing the same issue.

@zhuhanyuguluguluzhu
Copy link

哈哈哈哈

@github-actions github-actions bot locked and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants