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

Svelte 5: Actions and on: directives don't respect the order they are listed #11516

Open
Conduitry opened this issue May 8, 2024 · 3 comments
Labels
Milestone

Comments

@Conduitry
Copy link
Member

Describe the bug

In Svelte 4, putting a use: action followed by an on: event handler on an element would first attach the action and then attach the event handler. In Svelte 5, it looks like event handlers are attached before the actions, regardless of the order they are specified on the element.

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACnWQQW7DIBBFr4LY2JaidE-cSF101xvUXRAYp6h4xoIhUmX57gWHJN10A_z5_DcMixydhyjVxyJRTyCVfJ1nuZP8MxcRr-AZso6UgimVPprgZj4NOPCY0LAjFHrbWiQLnViKNXARe23t2xWQ311kQAhtY7wz381OtJ04noQhjORh7-lSLTEGmipQQMmKL43WQ2i67lDQa17-Nq92--j8HzTAJXkdnrw7rn95DoX9OTFnbIqg6jMI1YY5LjW6buPfLpb47ZSL-acmsm50YKXikGD9XH8B9L2B8mQBAAA=

Logs

No response

System Info

REPL

Severity

annoyance

@Conduitry Conduitry added the bug label May 8, 2024
@Conduitry Conduitry added this to the 5.0 milestone May 8, 2024
@Conduitry
Copy link
Member Author

In the generated code, I do see these in order

	$.action(button, ($$node) => action($$node));
	$.event("click", button, handler, false);

so I'm assuming that $.action isn't synchronously calling the action's function.

@Conduitry
Copy link
Member Author

@dummdidumm
Copy link
Member

Yes it's a result of event delegation, with #11435 as a proposal to possibly fix this.

The reason they run out of order is that action functions are executed in an effect, because else the dom isn't attached yet and certain stuff doesn't work correctly (I don't remember the details, if I do we should document this in the code). I'm not sure how to best fix this, if we want to fix this. Put listeners inside an effect, too? Bindings are already inside effects AFAIK so that order is preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants