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

Custom svelte event dispatch double-wraps data in event.detail.detail rather than event.detail #358

Open
bloombar opened this issue Mar 1, 2024 · 0 comments

Comments

@bloombar
Copy link

bloombar commented Mar 1, 2024

Using svelte's standard dispatch seems to wrap the detail field within another detail.

Inner.svelte:

 import { createEventDispatcher } from 'svelte'
 const dispatch = createEventDispatcher();

// at some point, dispatch a custom event
dispatch('customEvent', { 'foo': bar })

Outer.svelte:

import Inner from './Inner.svelte'

const doSomething = e => {
   console.log(JSON.stringify(e, null, 2)
}
// ...

<Inner on:customEvent={doSomething} />

Actual output

The event object, e, looks something like:

{
    "eventName":"customEvent",
    "type":"customEvent",
    "detail": {
        "detail": {
            "foo": "bar"
        },
      "bubbles":false,
      "cancelable":false
    }
}

So accessing the payload requires e.detail.detail.foo instead of e.detail.foo... note the recursive detail.

Expected output

Would expect the event object, e, to look something like:

{
    "eventName":"customEvent",
    "type":"customEvent",
    "detail": {
        "foo": "bar"
    }
   "bubbles":false,
   "cancelable":false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant