Subscribe on changes!

Custom event handler are missing from $attrs

avatar
Dec 4th 2021

Version

3.2.23

Reproduction link

jsfiddle.net/ronzwj6g/

Steps to reproduce

  1. Create a custom component
  2. Apply a listener for a custom event (e.g. @custom="..." and @other="..." as per the example)
  3. Observe how these are listed in $attrs of the component as $attrs.onCustom, $attrs.onOther etc.
  4. Now implement the custom event by adding emits: ['custom'] to the custom component
  5. Observe how $attrs.onCustom is now undefined
  6. As a result, there appears to be no way to detect if a custom event listener is present on a component or not

What is expected?

For custom event listeners to show up in $attrs even if the component has them in its emits array.

What is actually happening?

The listener is undefined


Refer to https://stackoverflow.com/questions/46706737/check-if-a-component-has-an-event-listener-attached-to-it for more details on the use case etc.

avatar
Dec 4th 2021

they are missing just like declared props are missing from $attrs.

We have an open issue about this already where we noted that we might consider a way to access cust event listeners like you can access props. Can't find it right now though.

For now, you can declare the listener as a prop with on* prefix (which is how listeners are passed under the hood anyway), then you can check props.onCustom.

avatar
Dec 4th 2021

Alright thanks, if you can find the open issue so that I (or anyone finding this in the future) can track the progress for it that would be much appreciated.

avatar
Dec 9th 2021

I'm interested in this as well and I can't seem to find a related issue.