svelteuidev / svelteui

SvelteUI Monorepo
https://svelteui.dev
MIT License
1.3k stars 62 forks source link

Checkbox onChange event called before value updated #291

Closed T-bond closed 1 year ago

T-bond commented 1 year ago

What package has an issue

@svelteuidev/core

A clear and concise description of what the bug is

Checkbox event callbacks do not keep order. Binding a change event handler after the value binding will call the change event before the value update event. In plain Svelte order of attributes are kept.

Related: https://github.com/svelteuidev/svelteui/issues/277

In which browser(s) did the problem occur?

Microsoft Edge

Steps To Reproduce

See sample code:

<input type="checkbox" on:change={() => console.log('Svelte before change', val)} bind:checked={val} on:change={() => console.log('Svelte after change', val)} />
{val}
<Checkbox on:change={() => console.log('SvelteUI before change', val2)} bind:checked={val2} on:change={() => console.log('SvelteUI after change', val2)} />
{val2}

Do you know how to fix the issue

No

Are you willing to participate in fixing this issue and create a pull request with the fix

No

Relevant Assets

image

BeeMargarida commented 1 year ago

From a first glance, this has to do with our current logic of event forwarding in components. However, I don't think this is fixable right now, even making a simple event forwarding for the on:change like they it shows in the Svelte docs - https://svelte.dev/tutorial/event-forwarding - this is not possible. As anyone have any idea of a solution?

BeeMargarida commented 1 year ago

I'm gonna create an issue on Svelte side so that this can be discussed. It seems like a very specific edge case, but it's interesting. I'll tag you

BeeMargarida commented 1 year ago

Gonna close this issue since it can be considered expected behaviour