-
-
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
Svelte 5: spreading attributes on a input changes event handlers behaviour #11138
Comments
I made a slightly different reproduction of the problem repl because I found that the problem is not about destructuring $props with a rest variable, but spreading attributes on the input. |
The behavior for this is non-deterministic, because it depends on which events fire in what order. Generally bindings need to happen after attributes have updated, and the spread puts the change event into the same bucket as the spread into one render effect. |
If you just add it to the documentation a simple input wrapper like this becomes a lot more verbose |
This is attempt 1 to fix #11138. The idea is that actions, bindings and event directives are added to the "spread attributes" function. That function then first sets all attributes, collects event attributes, then runs actions/bindings/event handlers, and then runs event attributes, to guarantee that event attributes run last. The sad thing is that it doesn't work. The problem is that bindings or actions could have effects inside them, and those effects would then be tied to the render effect surrounding the "spread attributes" function, and not to the block effect above it, leading to wrong rerun/destroy timings.
By running the event listener logic inside an effect on the first run we guarantee that they're attached after binding listeners. Fixes #11138.
By running the event listener logic inside an effect on the first run we guarantee that they're attached after binding listeners. Fixes #11138.
* fix: run event attributes after binding event listeners By running the event listener logic inside an effect on the first run we guarantee that they're attached after binding listeners. Fixes #11138. * give arrow functions stable id, better code gen * optimise normal function expressions too (rare but valid!) --------- Co-authored-by: Rich Harris <[email protected]>
Describe the bug
Hi, I made a simple component to wrap a checkbox and his style. I realized that if you use rest props while destructing $props rune, the onchange event is triggered with the wrong value.
When calling onchange checked value is wrong
When calling onchange checked value is right
Reproduction
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACrWSTUvEMBCG_8oQFraF2t7XNCgeRIRdUMGD9ZA2s7vBNAlJVpTS_y5xu-t-KR70kENmMu888046MpcKPZk8dUTzFsmEXFpLMhLebbz4V1QBSUa8WbkmRqhvnLSBVboKsrXGBbhaYvNSm7c79AHmzrQwzovdYL6WGZ-omZqTVevwbl08CgNwKGHkAw-YzLnymJ5_5erjnKbFF7Cmll2Z1hqNOkBY8gArjx7yPHeRYmSdsT5J4Qymswd4nN3d3kyvaWFZpenelEY3S64XWHZJCiWDxmhvFObKLBKe9lBLLSZNrEBRdrxnnO458g2NMOj1-JPqFFQEuj_AGQz8Cag-Aqp7VtMDs1mlSUZaI-RcoiCT4FbYZ9tvsUv_2_8Rd9LB0DXuJlLwWmGSZtAspRIOdbZlz7Yz9_HxMPeJHUZtqniNilGp7SpAxCkr0gyQFYFuo9pDN8juuwAFg-7CoRbotjBJ2tNirRzb2l-asnbw32wR0se0-GtfNrp_Zcxz_wEjEgCuUAQAAA==
Logs
No response
System Info
Severity
blocking all usage of svelte
The text was updated successfully, but these errors were encountered: