-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
event handlers are unbound when called with forwarded DOM events from child components #6310
Comments
I'm not an expert here, but here's what I'm seeing: In the When you are using the So I'm with you that |
@Prinzhorn This issue is about preserving the But yeah, |
@bluwy what I meant is that a consumer of |
@Prinzhorn I'm not sure if that's true. One way or another, the consumer of the component would need to know if it's a forwarded DOM event or a dispatched event. This can't be hidden internally since the In case of a forwarded DOM event, the event type would be e.g. |
|
Describe the bug
this
is undefined in event handlers, when handling a DOM event which has been forwarded from a child componentLogs
See repro
To Reproduce
The bug can be easily reproduced in the DOM Event Forwarding section of the tutorial. Click
Show me
, then replace thehandleClick
definition with:This caused confusion later in the tutorial, in the Lifecycle/tick section, where
this
in a handler refers toevent.target
.Expected behaviour
Unless this is intentional, I would expect consistency in how event handlers can be used regarding
this
. On the other hand, if usingthis
from event handlers is discouraged, the above-mentionedtick
section in the tutorial could useevent.target
insteadAdditional Context
A discord user pointed me to
svelte/src/runtime/internal/lifecycle.ts
Lines 64 to 70 in dafbdc2
event
here is the original DOM event, it may be as simple as calling the callback in the context ofevent.target
:In the event that
event.target
is undefined, we're back to where we started (this
is undefined)The text was updated successfully, but these errors were encountered: